Find out which remote branch a local branch is tracking
Here is a command that gives you all tracking branches (configured for 'pull'), see:
$ git branch -vv main aaf02f0 [main/master: ahead 25] Some other commit* master add0a03 [jdsumsion/master] Some commit
You have to wade through the SHA and any long-wrapping commit messages, but it's quick to type and I get the tracking branches aligned vertically in the 3rd column.
If you need info on both 'pull' and 'push' configuration per branch, see the other answer on git remote show origin
.
Update
Starting in git version 1.8.5 you can show the upstream branch with git status
and git status -sb
Two choices:
% git rev-parse --abbrev-ref --symbolic-full-name @{u}origin/mainline
or
% git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"origin/mainline
I think git branch -av
only tells you what branches you have and which commit they're at, leaving you to infer which remote branches the local branches are tracking.
git remote show origin
explicitly tells you which branches are tracking which remote branches. Here's example output from a repository with a single commit and a remote branch called abranch
:
$ git branch -av* abranch d875bf4 initial commit master d875bf4 initial commit remotes/origin/HEAD -> origin/master remotes/origin/abranch d875bf4 initial commit remotes/origin/master d875bf4 initial commit
versus
$ git remote show origin* remote origin Fetch URL: /home/ageorge/tmp/d/../exrepo/ Push URL: /home/ageorge/tmp/d/../exrepo/ HEAD branch (remote HEAD is ambiguous, may be one of the following): abranch master Remote branches: abranch tracked master tracked Local branches configured for 'git pull': abranch merges with remote abranch master merges with remote master Local refs configured for 'git push': abranch pushes to abranch (up to date) master pushes to master (up to date)