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


当前回答

我找到的最简单的方法是:

git branch -a

其他回答

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

git remote update --prune

这将使用远程的所有新分支列表更新本地分支列表,并删除不再存在的分支列表。在不使用--prune的情况下运行此更新命令将检索新分支,但不会删除远程上不再存在的分支。

您可以通过指定一个远程来加快此更新,否则它将从您添加的所有远程中提取更新,如下所示

git remote update --prune origin

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

gitbranch-r--sort=提交日期

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

最好运行的命令是gitremoteshow[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"

然后你可以运行git分支。

git branch -a | grep remotes/*

使用GitBash,您可以使用:

git branch -a