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


当前回答

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

其他回答

But

git分支-ar

应该这样做。

为了得到我想要的东西,我最后做了一个乱七八糟的外壳管道。我刚刚合并了源远程的分支:

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

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

git branch -a

remoteshow显示远程上的所有分支,包括那些本地未跟踪的分支,甚至那些尚未提取的分支。

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)

您还可以执行git fetch,后跟git branch-r。没有fetch,您将看不到最新的分支。