如何在 Git 1.7+ 中列出所有远程分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3471827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I list all remote branches in Git 1.7+?
提问by James A. Rosen
I've tried git branch -r
, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists allremote branches or only those that are untracked.)
我试过了git branch -r
,但只列出了我在本地跟踪的远程分支。我如何找到那些我没有的列表?(对我来说,该命令是列出所有远程分支还是仅列出未跟踪的分支并不重要。)
回答by Dustin
For the vast majority[1]of visitors here, the correct and simplest answer to the question"How do I list all remote branches in Git 1.7+?" is:
对于这里的绝大多数[1]访问者,问题“如何在 Git 1.7+ 中列出所有远程分支?”的正确和最简单的答案。是:
git branch -r
For a small minority[1]git branch -r
does not work. If git branch -r
does not work try:
对于少数人[1]git branch -r
不起作用。如果git branch -r
不起作用,请尝试:
git ls-remote --heads <remote-name>
If git branch -r
does not work, then maybe as Cascabelsays "you've modified the default refspec, so that git fetch
and git remote update
don't fetch all the remote
's branches".
如果git branch -r
不工作,那么也许是Cascabel说:“你已经修改了默认的Refspec,使git fetch
和git remote update
不获取所有remote
的分支”。
[1]As of the writing of this footnote 2018-Feb, I looked at the comments and see that the git branch -r
works for the vast majority (about 90% or 125out of 140).
[1]本脚注2018 - 2月的写作作为,我看了看评论,看到的git branch -r
绝大多数作品(约90%或125出的140)。
If git branch -r
does not work, check git config --get remote.origin.fetch
contains a wildcard (*
) as per this answer
如果git branch -r
不起作用,请根据此答案检查git config --get remote.origin.fetch
包含通配符 ( *
)
回答by Klas Mellbourn
remote show
shows all the branches on the remote, including those that are not tracked locally and even those that have not yet been fetched.
remote show
显示远程上的所有分支,包括本地未跟踪的分支,甚至尚未获取的分支。
git remote show <remote-name>
It also tries to show the status of the branches relative to your local repository:
它还尝试显示相对于本地存储库的分支状态:
> 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)
回答by Idan K
git branch -a | grep remotes/*
回答by Nick Gronow
Using git branch -r
lists all remote branches and git branch -a
lists all branches on local and remote. These lists get outdated though. To keep these lists up-to-date, run
使用git branch -r
列出所有远程分支并git branch -a
列出本地和远程的所有分支。不过,这些列表已经过时了。要使这些列表保持最新,请运行
git remote update --prune
which will update your local branch list with all new ones from the remote and remove any that are no longer there. Running this update command without the --prune will retrieve new branches but not delete ones no longer on the remote.
这将使用来自远程的所有新分支更新您的本地分支列表,并删除任何不再存在的分支列表。在没有 --prune 的情况下运行此更新命令将检索新分支,但不会删除远程上不再存在的分支。
You can speed up this update by specifying a remote, otherwise it will pull updates from all remotes you have added, like so
您可以通过指定遥控器来加速此更新,否则它将从您添加的所有遥控器中提取更新,如下所示
git remote update --prune origin
回答by Seakayone
But
但
git branch -ar
git branch -ar
should do it.
应该这样做。
回答by Max Sohrt
You also may do git fetch
followed by a git branch -r
. Without fetch you will not see the most current branches.
你也可以在git fetch
后面跟着一个git branch -r
. 如果没有 fetch,您将看不到最新的分支。
回答by Michael Horojanski
回答by Damián Rafael Lattenero
The simplest way I found:
我发现的最简单的方法:
git branch -a
回答by simhumileco
TL;TR;
TL;TR;
This is the solution of your problem:
这是您问题的解决方案:
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
回答by Anubian Noob
The best command to run is git remote show [remote]
. This will show all branches, remote and local, tracked and untracked.
运行的最佳命令是git remote show [remote]
. 这将显示所有分支,远程和本地,已跟踪和未跟踪。
Here's an example from an open source project:
下面是一个开源项目的例子:
> 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)
If we just want to get the remote branches, we can use grep
. The command we'd want to use would be:
如果我们只想获取远程分支,我们可以使用grep
. 我们想要使用的命令是:
grep "\w*\s*(new|tracked)" -E
With this command:
使用此命令:
> 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
You can also create an alias for this:
您还可以为此创建别名:
git config --global alias.branches "!git remote show origin | grep \w*\s*(new|tracked) -E"
Then you can just run git branches
.
然后你就可以运行了git branches
。