我尝试过gitbranch-r,但它只列出了我在本地跟踪的远程分支。我如何找到我没有的列表?(该命令是否列出所有远程分支或仅列出未跟踪的分支对我来说无关紧要。)
当前回答
使用该命令,
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。
其他回答
您还可以执行git fetch,后跟git branch-r。没有fetch,您将看不到最新的分支。
确保列出的远程源确实是所需的存储库,而不是较旧的克隆。
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)
最好运行的命令是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分支。
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