繁体   English   中英

找出本地分支正在跟踪哪个远程

[英]Find out which remote a local branch is tracking

不是找出本地分支正在跟踪哪个远程分支,如果我有多个远程,我可能在所有远程分支中都有“master”。 git branch返回 master 但我不知道我所在的 master 分支是在 remoteFoo 还是 remoteBar。 例如,我可能会这样做:

git clone someRepo.git
cd someRepo
git remote add anotherRemote otherremoteURL

然后git remote显示

someRepo
anotherRemote

我可以执行git checkout -b master someRepo/mastergit checkout -b master anotherRemote/mastergit branch在这两种情况下都会说“master”。 如何取回第一部分“someRepo”或“anotherRemote”?

你可能认为我可以使用git remote show但它需要一个参数,即你想要获取信息的遥控器的名称。

$ git remote show origin
fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
$ git remote show
someRepo
anotherRemote

通过git branch ,我得到了当前的指示:

$ git branch
  hold
* master
  old-stuff
  refactor

但是git remote output中没有“*”。

您可能想在下面尝试这些以查看详细信息。

git remote -v
git remote -v show origin

下面的示例输出:

dmasi@:/var/www/pirate_booty$ git remote -v
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (fetch)
origin  git@bitbucket.org:dmasi/pirate_booty_calculator.git (push)

dmasi@:/var/www/pirate_booty$ git remote -v show origin
* remote origin
  Fetch URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  Push  URL: git@bitbucket.org:dmasi/pirate_booty_calculator.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

git status -sb似乎易于理解和记住。

-s代表以短格式给出输出。

b用于显示分支和跟踪信息。

参考: https : //git-scm.com/docs/git-status#git-status--s

这是回答类似的问题在这里 :让当前分支正在跟踪远程分支,

git rev-parse --symbolic-full-name --abbrev-ref @{u}

使用命令'git branch -l -vv'

参考: https://git-scm.com/docs/git-branch

-v

-vv

--冗长

在列表模式下,显示每个头的 sha1 和提交主题行,以及与上游分支的关系(如果有)。 如果给出两次,则打印链接工作树的路径(如果有)和上游分支的名称(另请参见 git remote show )。 请注意,当前工作树的 HEAD 不会打印其路径(它始终是您的当前目录)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM