7

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.

Community
  • 1
  • 1
Chris Nelson
  • 3,519
  • 7
  • 40
  • 51
  • How exactly is it not the same as the referenced question? [This answer](http://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking/7733266#7733266) seems to give details about the remote branches tracked by your local branches; if you do `git checkout someRepo/master`, git will explicitly tell you that you're in a detached HEAD state and `git branch` will say `(no branch)`, and not `master` as you think it would. – lanzz Sep 26 '12 at 20:06
  • Maybe I missed it but I don't see anyhere in that question that any of the commands show you the remote for the current branch, only the branch name. – Chris Nelson Sep 26 '12 at 20:10
  • `git branch` gives you the name of the current branch, and `git remote show origin` tells you which local branch tracks which remote. Probably there won't be a specific command that handles your specific case in the specific way you would want it. – lanzz Sep 26 '12 at 20:11

4 Answers4

18

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)
thameera
  • 9,168
  • 9
  • 37
  • 38
beenhere4hours
  • 970
  • 9
  • 12
  • Thank you! `git remote` lists all my remotes and `git remote -v` shows the status of the current one so I can take the first word of the first line of that output and use it as my current remote. – Chris Nelson Sep 27 '12 at 12:04
13

git status -sb seems easy to understand and remember.

-s stands for Give the output in the short-format.

b for Show the branch and tracking info.

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

Sanket Patel
  • 541
  • 6
  • 12
4

This is answered in a similar question here: to get the remote branch being tracked by the current branch,

git rev-parse --symbolic-full-name --abbrev-ref @{u}
Community
  • 1
  • 1
Duncan Macleod
  • 1,045
  • 11
  • 21
  • That gives me errors (error: No upstream configured for branch 'master'). What version of `git` are you using? I'm in 1.7.11.3. – Chris Nelson Sep 26 '12 at 20:21
  • 1.7.12. If you don't have an upstream branch then there's probably another issue. Is this a new branch, and have you pushed it to the remote? What is the output of git branch -a? – Duncan Macleod Sep 26 '12 at 20:49
1

Use command 'git branch -l -vv'

Reference: https://git-scm.com/docs/git-branch

-v

-vv

--verbose

When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the path of the linked worktree (if any) and the name of the upstream branch, as well (see also git remote show ). Note that the current worktree’s HEAD will not have its path printed (it will always be your current directory).