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

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

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


当前回答

你可以试试这个:

git remote show origin | grep "branch_name"

Branch_name需要替换为您的分支

其他回答

还有另一种方法

git status -b --porcelain

这会给你

## BRANCH(...REMOTE)
modified and untracked files

grep 'BRANCH_NAME'

git branch -vv:该部分将显示所有本地分支及其上游分支。

grep 'BRANCH_NAME':它将从分支列表中过滤当前分支。

改进这个答案,我想出了这些.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 -ra

输出:

  feature/feature1
  feature/feature2
  hotfix/hotfix1
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master

下面的命令将远程原点电流叉指的是

Git remote -v

添加远程路径时,

Git远程添加原始路径_name