参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?

如何知道本地分支正在跟踪哪个远程分支?

我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?


当前回答

我不知道这是否算作解析git配置的输出,但这将确定master正在跟踪的远程服务器的URL:

$ git config remote.$(git config branch.master.remote).url

其他回答

我不知道这是否算作解析git配置的输出,但这将确定master正在跟踪的远程服务器的URL:

$ git config remote.$(git config branch.master.remote).url
git branch -r -vv

将列出所有分支,包括远程分支。

你可以试试这个:

git remote show origin | grep "branch_name"

Branch_name需要替换为您的分支

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)

不使用grep只显示当前分支信息:

git branch -vv --contains

这是缩写:

git branch -vv --contains HEAD

如果你当前的HEAD的提交id在其他分支中,这些分支也会显示。