After creating a branch with --track (or leaving the default, or --notrack), you later wish to be reminded of what a branch is tracking. Is there a way, other than searching through the .git/config file, to display what a branch is tracking?
5 Answers
Use: git branch -vv
to see which branches are tracked and which are not.

- 109,858
- 19
- 140
- 171
Note that with git1.8.3 (April 22d, 2013), you have a new way to emphasize the upstream branch:
"
git branch -vv
" learned to paint the name of the branch it integrates with in a different color (color.branch.upstream
, which defaults to blue).
C:\prog\git\git>git branch -vv
* master 118f60e [origin/master] Sync with maint
^^^^^^^^^^^^^
|
--- now in blue
-
that part is not colored for for me. I am on mac 1.8.4. Anybody know why? – dongshengcn Oct 29 '13 at 18:18
-
1@dongshengcn yes, I like setting `git config color.ui always`: https://gist.github.com/VonC/972690#file-gitconfig-L25 – VonC Oct 30 '13 at 07:00
-
1I think that should be `git branch -vv` in the quote box – Faramarz Salehpour Jan 30 '17 at 08:25
-
what does **vv** stand for? https://git-scm.com/docs/git-branch#git-branch--vv – Tim Boland Mar 09 '17 at 01:20
-
2@TimBoland it stands for "extra verbose" – VonC Mar 09 '17 at 05:24
If you want to know for a given branch, you could do:
git config --get branch.<branch>.remote
If it prints a remote, it's tracking something. If it prints nothing and returns failure, it's not.

- 479,068
- 72
- 370
- 318
-
That is nice for getting the repository, but it doesn't get the branch name (which may be different) – Casebash Jan 09 '12 at 06:56
-
@Casebash: True, but that's a *very* rare situation, and if you know you're in it, you can grab another config variable. This has the benefit (compared to `git branch -vv`) of not having extraneous output (i.e. it's machine-parseable). It will sometimes be useful. – Cascabel Jan 09 '12 at 14:24
-
I'll add for the benefit of other people that the config variable for the branch name is `branch.fees.merge` – Casebash Jan 09 '12 at 23:34
If you need to access this information in an automated fashion you will want to avoid trying to parse the output of branch -vv
(slebetman’s answer).
Git provides a set of lower-level commands with stable interfaces and output formats. These commands (called “plumbing”) are the preferred interface for ‘scripting’ purposes. The git for-each-ref command can provide the required information via the upstream
token (available in Git 1.6.3 and later):
% git for-each-ref --shell --format='
b=%(refname:short) u=%(upstream:short)
# Make a fancy report or do something scripty with the values.
if test -n "$u"; then
printf "%s merges from %s\n" "$b" "$u"
else
printf "%s does not merge from anything\n" "$b"
fi
' refs/heads/ | sh
master merges from origin/master
other does not merge from anything
pu merges from origin/pu

- 1
- 1

- 214,407
- 26
- 209
- 186
Thanks for the hint Jefromi
With the following command you can get the remote tracking branch for a specific branch.
git config --get branch.<branch>.merge
To change the remote tracking branch you can simply change this config value.
Note: this is an alternative way to git branch -vv
(already answered here)
and git branch -u
(Make an existing Git branch track a remote branch?)