参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
当前回答
我不知道这是否算作解析git配置的输出,但这将确定master正在跟踪的远程服务器的URL:
$ git config remote.$(git config branch.master.remote).url
其他回答
改进这个答案,我想出了这些.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 branch -vv
所有分支和跟踪遥控器。
git branch -a -vv
查看本地分支在哪里显式地配置了推和拉。
git remote show {remote_name}
不使用grep只显示当前分支信息:
git branch -vv --contains
这是缩写:
git branch -vv --contains HEAD
如果你当前的HEAD的提交id在其他分支中,这些分支也会显示。
我不知道这是否算作解析git配置的输出,但这将确定master正在跟踪的远程服务器的URL:
$ git config remote.$(git config branch.master.remote).url
git branch -vv | grep 'hardcode-branch-name'
# "git rev-parse --abbrev-ref head" will get your current branch name
# $(git rev-parse --abbrev-ref head) save it as string
# find the tracking branch by grep filtering the current branch
git branch -vv | grep $(git rev-parse --abbrev-ref head)