Git存储库的远程列表?

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

比如git list --remotes之类的?

647376 次浏览

您可以使用命令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 remote就足够了。

$ 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 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会很方便,而不是通过源传递所有内容。

这些方法都没有像提问者要求的那样工作,我也经常需要这种方法。例如:

$ 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的问题。虽然它仍然会很好。