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

比如git列表,遥控器之类的?


当前回答

您可以使用命令git remote -v获取任何已配置的远程url的列表。

这将为您提供如下内容:

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

其他回答

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

$ git remote
iqandreas
octopress
origin

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

git branch -r

查看本地分支机构:

git branch -l

FWIW,我也有同样的问题,但我在这里找不到答案。它可能是不可移植的,但至少对于gitolite,我可以运行以下命令来得到我想要的:

$ 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
...

这些方法都不能满足提问者的要求,而这也是我经常需要的。例如:

$ 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的问题。如果有的话还是很不错的。

到目前为止,答案告诉你如何找到现有的分支:

git branch -r

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

git remote -v

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

为了发现这些信息,我使用SSH或PuTTY登录到host和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只告诉我项目的来源——我克隆项目的存储库。如果您与两个或多个工作在同一个项目上的人合作,并且直接访问彼此的存储库,而不是通过原始文件传递所有内容,那么Git远程将非常方便。