Git仓库的遥控器列表?


542

我有一个Git存储库。这个存储库有多个远程存储库(我认为)。如何获得属于所述存储库的远程存储库的列表?

喜欢git list --remotes还是类似的东西?

Answers:


749

您可以使用命令获取所有已配置的远程URL的列表git remote -v

这将为您提供如下信息:

base    /home/***/htdocs/base (fetch)
base    /home/***/htdocs/base (push)
origin  git@bitbucket.org:*** (fetch)
origin  git@bitbucket.org:*** (push)

18
git remote -v因为-v是冗长的。 git remote给出了一个简单的遥控器列表(在这种情况下为基本,原点)。-v选项包括每个远程的提取和推送操作的URL。
dhj

2
我必须同意@AlexMills,如果它是git branch --list,则应该是git remote --list
jimmyb 2015年

1
-v“冗长”实际上是更常见的选择。也受到的支持git branch。基本的区别是长选项和短选项(基本上是双破折号),也就是说,用remote子命令支持--list是有意义的。如果您真的想要,我会说提交功能请求。
兰德尔

4
这需要一个已经有一个克隆。当试图弄清楚要开始克隆什么时,还需要其他一些方法……
Mikhail T.

60

如果您只需要远程存储库的名称(而不需要其他任何数据),那么简单git remote就足够了。

$ git remote
iqandreas
octopress
origin

32

FWIW,我有完全相同的问题,但在这里找不到答案。它可能不是便携式的,但至少对于乙醇钠矿,我可以运行以下命令以获取所需的东西:

$ ssh git@git.xxx.com info
hello akim, this is gitolite 2.3-1 (Debian) running on git 1.7.10.4
the gitolite config gives you the following access:
     R   W     android
     R   W     bistro
     R   W     checkpn
...

24

到目前为止的答案告诉您如何查找现有分支机构:

git branch -r

或同一项目的存储库[请参见下面的注释]

git remote -v

还有另一种情况。您可能想知道同一服务器上托管的其他项目存储库。

为了发现该信息,我使用SSH或PuTTY登录到主机并ls查找包含其他存储库的目录。例如,如果我通过键入以下内容来克隆存储库:

git clone ssh://git.mycompany.com/git/ABCProject

并想知道还有什么可用,我通过SSH或PuTTY登录到git.mycompany.com并键入:

ls /git

假设ls说:

 ABCProject DEFProject

我可以使用命令

 git clone ssh://git.mycompany.com/git/DEFProject

获得访问另一个项目的权限。

注意:通常git remote只告诉我有关origin-从中克隆项目的存储库的信息。 git remote如果您与两个或多个从事同一项目的人员合作,并且直接访问彼此的存储库,而不是将所有内容都传递给原始人,则将很方便。


2
这是一个更好的答案,因为它谈论的是存储库,而不是分支,并说明了如何列出当前未检出存储库中的存储库
Edward Ross

16

查看远程分支的一种简单方法是:

git branch -r

要查看本地分支机构:

git branch -l

15
这是用于远程分支机构;用户要求远程回购
Owen Blacker 2014年

4
git ls-remote应该会向您显示所有可用于从上游服务器提取的远程(git-scm.com/docs/git-ls-remote)。我相信此页面上的所有答案只会告诉您如何列出已获取的遥控器和跟踪分支,即Catch-22。您必须先知道如何在上游服务器上引用远程,然后才能获取远程。
Reb.Cabin '16

0

这些方法都无法按照发问者的要求以及我经常需要的方式工作。例如:

$ git remote
fatal: Not a git repository (or any of the parent directories): .git
$ git remote user@bserver
fatal: Not a git repository (or any of the parent directories): .git
$ git remote user@server:/home/user
fatal: Not a git repository (or any of the parent directories): .git
$ git ls-remote
fatal: No remote configured to list refs from.
$ git ls-remote user@server:/home/user
fatal: '/home/user' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

这样做的全部目的是,除了远程用户和服务器之外,您没有其他任何信息,并且想找出您有权访问的内容。

大多数答案都假设您正在git工作集中进行查询。发问者认为你不是。

作为一个实际示例,假设服务器上有一个存储库foo.git。有人认为他们需要将其更改为foo2.git。列出服务器上的git目录列表确实很棒。是的,我看到了git的问题。仍然会很高兴。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.