我尝试过gitbranch-r,但它只列出了我在本地跟踪的远程分支。我如何找到我没有的列表?(该命令是否列出所有远程分支或仅列出未跟踪的分支对我来说无关紧要。)
当前回答
git branch -a | grep remotes/*
其他回答
对于这里的绝大多数访问者来说,“我如何在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--全部
TL;TR;
这是您问题的解决方案:
git remote update --prune # To update all remotes
git branch -r # To display remote branches
or:
git remote update --prune # To update all remotes
git branch <TAB> # To display all branches
为了得到我想要的东西,我最后做了一个乱七八糟的外壳管道。我刚刚合并了源远程的分支:
git branch -r --all --merged \
| tail -n +2 \
| grep -P '^ remotes/origin/(?!HEAD)' \
| perl -p -e 's/^ remotes\/origin\///g;s/master\n//g'