参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
当前回答
grep 'BRANCH_NAME'
git branch -vv:该部分将显示所有本地分支及其上游分支。
grep 'BRANCH_NAME':它将从分支列表中过滤当前分支。
其他回答
我用这个别名
git config --global alias.track '!sh -c "
if [ \$# -eq 2 ]
then
echo \"Setting tracking for branch \" \$1 \" -> \" \$2;
git branch --set-upstream \$1 \$2;
else
git for-each-ref --format=\"local: %(refname:short) <--sync--> remote: %(upstream:short)\" refs/heads && echo --URLs && git remote -v;
fi
" -'
then
git track
注意,该脚本还可以用于设置跟踪。
更多很棒的别名请访问https://github.com/orefalo/bash-profiles
我使用EasyGit(又名:EasyGit)。"eg")作为Git顶部(或旁边)的超轻量级包装器。EasyGit有一个“info”子命令,它为您提供各种超级有用的信息,包括当前分支的远程跟踪分支。下面是一个例子(当前分支名称是"foo"):
pknotz@s883422: (foo) ~/workspace/bd $ eg info Total commits: 175 Local repository: .git Named remote repositories: (name -> location) origin -> git://sahp7577/home/pknotz/bd.git Current branch: foo Cryptographic checksum (sha1sum): bd248d1de7d759eb48e8b5ff3bfb3bb0eca4c5bf Default pull/push repository: origin Default pull/push options: branch.foo.remote = origin branch.foo.merge = refs/heads/aal_devel_1 Number of contributors: 3 Number of files: 28 Number of directories: 20 Biggest file size, in bytes: 32473 (pygooglechart-0.2.0/COPYING) Commits: 62
两个选择:
% git rev-parse --abbrev-ref --symbolic-full-name @{u}
origin/mainline
or
% git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"
origin/mainline
在尝试了这里所有的解决方案后,我意识到没有一个解决方案在所有情况下都是好的:
在当地分公司工作 分离分支的工作 在CI公司工作
该命令获取所有名称:
git branch -a --contains HEAD --list --format='%(refname:short)'
对于我的应用程序,我必须过滤掉HEAD和master引用,更喜欢远程引用,并去掉单词“origin/”。然后如果没有找到,使用第一个没有/或a(的非HEAD引用。
git branch -r -vv
将列出所有分支,包括远程分支。