Find out which remote a local branch is tracking

This is not Find out which remote branch a local branch is tracking, If I have mulitple remotes, I might have "master" in all of them. git branch returns master but I don't know if the master branch I'm on is in remoteFoo or remoteBar. For example, I might do:

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

Then git remote shows

someRepo
anotherRemote

I can do git checkout -b master someRepo/master or git checkout -b master anotherRemote/master and git branch will say "master" in both cases. How do I get back the first part, "someRepo" or "anotherRemote"?

You'd think I could use git remote show but it requires an argument, the name of the remote you want information on.

$ 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

With git branch I get an indication of what is current:

$ git branch
  hold
* master
  old-stuff
  refactor

but there's no "*" in git remote output.


You may want to try these below to view in detail the information.

git remote -v
git remote -v show origin

Example output below:

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 rev-parse --symbolic-full-name --abbrev-ref @{u}
链接地址: http://www.djcxy.com/p/19510.html

上一篇: 使用PowerShell获取当前git分支的名称

下一篇: 找出本地分支正在跟踪哪个远程