参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
参见: 如何查看哪个Git分支正在跟踪哪个远程/上游分支?
如何知道本地分支正在跟踪哪个远程分支?
我是否需要解析git配置输出,或者是否有一个命令可以为我做这件事?
当前回答
如果你想找到任何分支的上游(而不仅仅是你所在的分支),这里是对@cdunn2001的答案的轻微修改:
git revv -parse——abbrev-ref——symbol -full-name
这将为名为YOUR_LOCAL_BRANCH_NAME的本地分支提供远程分支名称。
其他回答
另一种简单的方法是使用
Cat .git/config在一个git回购
这将列出本地分支的详细信息
下面的命令将远程原点电流叉指的是
Git remote -v
添加远程路径时,
Git远程添加原始路径_name
不使用grep只显示当前分支信息:
git branch -vv --contains
这是缩写:
git branch -vv --contains HEAD
如果你当前的HEAD的提交id在其他分支中,这些分支也会显示。
改进这个答案,我想出了这些.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
我使用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