如何在Git 1.7+中列出所有远程分支?

时间:2010-08-12 20:37:34

标签: git branch git-branch remote-branch

我已经尝试了git branch -r,但这只列出了我在本地跟踪的远程分支。我如何找到那些我没有的列表? (对我来说,命令是否列出所有远程分支或仅列出未跟踪的分支并不重要。)

20 个答案:

答案 0 :(得分:644)

对于绝大多数访问者 [1] the correct and simplest answer to the question“如何在Git 1.7+中列出所有远程分支?”是:

git branch -r

对于少数人来说, [1] git branch -r不起作用。如果git branch -r不起作用,请尝试:

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

如果git branch -r不起作用,那么可能会Cascabel"you've modified the default refspec, so that git fetch and git remote update don't fetch all the remote's branches"


[1] 截至2018年2月的脚注编写时,我查看了评论,发现git branch -r适用于绝大多数(约90%或{{{ 3}}出125)。

如果git branch -r不起作用,请按140

检查git config --get remote.origin.fetch是否包含通配符(*

答案 1 :(得分:154)

remote show显示遥控器上的所有分支,包括那些未在本地跟踪的分支,甚至是那些尚未获取的分支。

git remote show <remote-name>

它还会尝试显示分支相对于本地仓库的状态:

> git remote show origin
* remote origin
  Fetch URL: C:/git/.\remote_repo.git
  Push  URL: C:/git/.\remote_repo.git
  HEAD branch: master
  Remote branches:
    branch_that_is_not_even_fetched new (next fetch will store in remotes/origin)
    branch_that_is_not_tracked      tracked
    branch_that_is_tracked          tracked
    master                          tracked
  Local branches configured for 'git pull':
    branch_that_is_tracked merges with remote branch_that_is_tracked
    master                 merges with remote master
  Local refs configured for 'git push':
    branch_that_is_tracked pushes to branch_that_is_tracked (fast-forwardable)
    master                 pushes to master                 (up to date)

答案 2 :(得分:47)

git branch -a | grep remotes/*

答案 3 :(得分:36)

使用git branch -r列出所有远程分支,git branch -a列出本地和远程的所有分支。这些列表虽然过时了。要使这些列表保持最新,请运行

git remote update --prune

将使用来自遥控器的所有新分支列表更新本地分支列表,并删除任何不再存在的分支列表。在没有--prune的情况下运行此更新命令将检索新分支,但不再删除远程分支上的分支。

您可以通过指定遥控器来加速此更新,否则它会从您添加的所有遥控器中提取更新,如此

git remote update --prune origin

答案 4 :(得分:29)

但是

git branch -ar

应该这样做。

答案 5 :(得分:18)

Git Branching - 远程分支

git ls-remote

Git documentation

答案 6 :(得分:17)

您也可以git fetch后跟git branch -r。如果没有获取,您将看不到最新的分支。

答案 7 :(得分:9)

我找到的最简单的方法:

git branch -a

答案 8 :(得分:6)

<强> TL; TR;

这是您的问题的解决方案:

git remote update --prune    # To update all remotes
git branch -r                # To display remote branches

或:

git remote update --prune    # To update all remotes
git branch <TAB>             # To display all branches

答案 9 :(得分:5)

要运行的最佳命令是typedef enum { unsigned int x = 1 << 0, unsigned int y = 1 << 1 }statusBits2; 。这将显示所有分支,远程和本地,跟踪和未跟踪。

这是一个来自开源项目的例子:

git remote show [remote]

如果我们只想获得远程分支,我们可以使用> git remote show origin * remote origin Fetch URL: https://github.com/OneBusAway/onebusaway-android Push URL: https://github.com/OneBusAway/onebusaway-android HEAD branch: master Remote branches: amazon-rc2 new (next fetch will store in remotes/origin) amazon-rc3 new (next fetch will store in remotes/origin) arrivalStyleBDefault new (next fetch will store in remotes/origin) develop tracked master tracked refs/remotes/origin/branding stale (use 'git remote prune' to remove) Local branches configured for 'git pull': develop merges with remote develop master merges with remote master Local refs configured for 'git push': develop pushes to develop (local out of date) master pushes to master (up to date) 。我们想要使用的命令是:

grep

使用此命令:

grep "\w*\s*(new|tracked)" -E

您还可以为此创建别名:

> git remote show origin | grep "\w*\s*(new|tracked)" -E
    amazon-rc2                   new (next fetch will store in remotes/origin)
    amazon-rc3                   new (next fetch will store in remotes/origin)
    arrivalStyleBDefault         new (next fetch will store in remotes/origin)
    develop                      tracked
    master                       tracked

然后你可以运行git config --global alias.branches "!git remote show origin | grep \w*\s*(new|tracked) -E"

答案 10 :(得分:3)

使用GitBash,您可以使用:

  

git branch -a

答案 11 :(得分:3)

接受的答案对我有用。但是我发现从最近开始对提交进行排序更为有用。

git branch -r --sort=-committerdate

https://git-scm.com/docs/git-branch

答案 12 :(得分:1)

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

答案 13 :(得分:0)

确保您列出的远程源是您想要的存储库,而不是旧克隆。

答案 14 :(得分:0)

我最终做了一个混乱的shell管道来获得我想要的东西,只是从原始远程合并分支:

git branch -r --all --merged \
    | tail -n +2 \
    | grep -P '^  remotes/origin/(?!HEAD)' \
    | perl -p -e 's/^  remotes\/origin\///g;s/master\n//g'

答案 15 :(得分:0)

使用此命令,

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。

答案 16 :(得分:0)

尝试一下。...

git fetch origin
git branch -a

答案 17 :(得分:0)

我会使用:

git branch -av

此命令不仅向您显示所有分支的列表,包括以/remote开头的远程分支,还向您提供*关于更新内容和最后提交注释的反馈。

答案 18 :(得分:0)

如果有一个您应该列出的远程分支,但没有列出,则您可能要使用以下命令验证您的来源设置正确:

git remote show origin

如果这一切都很好,也许您应该运行一个更新:

git remote update

假设运行成功,您应该能够执行其他回答:

git branch -r

答案 19 :(得分:-3)

尝试

 git branch -at