Jam*_*sen 570 git branch remote-branch git-branch
我试过了git branch -r,但那只列出了我在本地跟踪的远程分支.我如何找到那些我没有的列表?(对我来说,命令是列出所有远程分支还是仅列出未跟踪的分支并不重要.)
Dus*_*tin 707
对于这里的绝大多数[1]访问者来说,对于如何列出Git 1.7+中所有远程分支的问题的正确和最简单的答案?是:
git branch -r
Run Code Online (Sandbox Code Playgroud)
少数人[1] git branch -r不起作用.如果git branch -r不起作用,请尝试:
git ls-remote --heads <remote-name>
Run Code Online (Sandbox Code Playgroud)
如果git branch -r不起作用,那么可能正如Cascabel所说"你已经修改了默认的git fetchgit remote updateremoterefspec ,所以并且不会获取所有的分支".
[1]作为这一脚注2018 - 2月的写作,我看着意见和看到git branch -r的作品绝大多数(约90%或125出的140).
如果git branch -r不起作用,请根据此答案检查git config --get remote.origin.fetch包含通配符(*)
Kla*_*urn 163
remote show 显示遥控器上的所有分支,包括那些未在本地跟踪的分支,甚至是那些尚未获取的分支.
git remote show <remote-name>
Run Code Online (Sandbox Code Playgroud)
它还会尝试显示相对于本地仓库的分支的状态:
> 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)
Run Code Online (Sandbox Code Playgroud)
Ida*_*n K 51
git branch -a | grep remotes/*
Run Code Online (Sandbox Code Playgroud)
Nic*_*now 39
使用git branch -r列出所有远程分支并git branch -a列出本地和远程的所有分支.这些列表虽然过时了.要使这些列表保持最新,请运行
git remote update --prune
Run Code Online (Sandbox Code Playgroud)
这将使用来自遥控器的所有新分支更新您的本地分支列表,并删除任何不再存在的分支列表.在没有--prune的情况下运行此更新命令将检索新分支但不删除远程不再分支的分支.
您可以通过指定遥控器来加速此更新,否则它将从您添加的所有遥控器中提取更新,如此
git remote update --prune origin
Run Code Online (Sandbox Code Playgroud)
Sea*_*one 28
但
git branch -ar
应该这样做.
TL; TR;
这是您的问题的解决方案:
git remote update --prune # To update all remotes
git branch -r # To display remote branches
Run Code Online (Sandbox Code Playgroud)
要么:
git remote update --prune # To update all remotes
git branch <TAB> # To display all branches
Run Code Online (Sandbox Code Playgroud)
小智 9
假设您在远程存储库上有以下分支:
git branch -a为您提供:
*remotes/origin/release/1.5.0
remotes/origin/release/1.5.1
remotes/origin/release/1.5.2
remotes/origin/release/1.5.3
remotes/origin/release/1.6.0
Run Code Online (Sandbox Code Playgroud)
基于上面的结果命令git branch -rl '*/origin/release/1.5*'给你这个:
origin/release/1.5.1
origin/release/1.5.2
origin/release/1.5.3
Run Code Online (Sandbox Code Playgroud)
-r代表远程
-l列出使用<pattern>
我会用:
git branch -av
Run Code Online (Sandbox Code Playgroud)
此命令不仅显示所有分支的列表,包括以 开头的远程分支/remote,而且还为您提供*有关更新内容和上次提交注释的反馈。
最好的命令是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)
Run Code Online (Sandbox Code Playgroud)
如果我们只想获得远程分支,我们就可以使用grep.我们想要使用的命令是:
grep "\w*\s*(new|tracked)" -E
Run Code Online (Sandbox Code Playgroud)
使用此命令:
> 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
Run Code Online (Sandbox Code Playgroud)
您还可以为此创建别名:
git config --global alias.branches "!git remote show origin | grep \w*\s*(new|tracked) -E"
Run Code Online (Sandbox Code Playgroud)
然后你就可以跑了git branches.
接受的答案对我有用。但是我发现从最近的提交开始排序更有用。
git branch -r --sort=-committerdate
| 归档时间: |
|
| 查看次数: |
408546 次 |
| 最近记录: |