参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
当前回答
我用这个别名
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
其他回答
这是一个命令,给你所有的跟踪分支(配置为'pull'),请参阅:
$ git branch -vv
main aaf02f0 [main/master: ahead 25] Some other commit
* master add0a03 [jdsumsion/master] Some commit
您必须费力地浏览SHA和任何长包装提交消息,但它可以快速输入,并且我在第三列中垂直对齐跟踪分支。
如果你需要每个分支的“拉”和“推”配置的信息,请参阅git remote show origin上的另一个答案。
更新
从git 1.8.5版本开始,你可以用git status和git status -sb来显示上游分支
我用这个别名
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
另一种简单的方法是使用
Cat .git/config在一个git回购
这将列出本地分支的详细信息
改进这个答案,我想出了这些.gitconfig别名:
branch-name = "symbolic-ref --short HEAD"
branch-remote-fetch = !"branch=$(git branch-name) && git config branch.\"$branch\".remote || echo origin #"
branch-remote-push = !"branch=$(git branch-name) && git config branch.\"$branch\".pushRemote || git config remote.pushDefault || git branch-remote-fetch #"
branch-url-fetch = !"remote=$(git branch-remote-fetch) && git remote get-url \"$remote\" #" # cognizant of insteadOf
branch-url-push = !"remote=$(git branch-remote-push ) && git remote get-url --push \"$remote\" #" # cognizant of pushInsteadOf
你可以试试这个:
git remote show origin | grep "branch_name"
Branch_name需要替换为您的分支