我尝试过gitbranch-r,但它只列出了我在本地跟踪的远程分支。我如何找到我没有的列表?(该命令是否列出所有远程分支或仅列出未跟踪的分支对我来说无关紧要。)


当前回答

使用GitBash,您可以使用:

git branch -a

其他回答

使用GitBash,您可以使用:

git branch -a

But

git分支-ar

应该这样做。

对于这里的绝大多数访问者来说,“我如何在Git 1.7+中列出所有远程分支?”这个问题的正确和最简单的答案是:

git branch -r

对于少数[1]git分支-r不起作用。如果gitbranch-r不起作用,请尝试:

git ls-remote --heads <remote-name>

如果git branch-r不起作用,那么可能正如Cascabel所说的“您修改了默认的refspec,这样git fetch和git remote update就不会获取所有远程的分支”。


[1] 在撰写本脚注2018年2月时,我查看了评论,发现git branch-r适用于绝大多数人(约90%或140人中的125人)。

如果gitbranch-r不起作用,请检查git-config-get-remote.origin.fetch是否包含通配符(*)

只需运行git fetch命令。它会将所有远程分支拉到本地存储库中,然后执行git branch-a以列出所有分支。

使用该命令,

git log -r --oneline --no-merges --simplify-by-decoration --pretty=format:"%n %Cred CommitID %Creset: %h %n %Cred Remote Branch %Creset :%d %n %Cred Commit Message %Creset: %s %n"

CommitID       : 27385d919
Remote Branch  : (origin/ALPHA)
Commit Message :  New branch created

它列出了所有远程分支,包括远程分支引用的提交消息和提交ID。