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?
+2
A:
Use: git branch -vv
to see which branches are tracked and which are not.
slebetman
2010-09-02 22:28:45
+1
A:
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.
Jefromi
2010-09-02 23:54:39
A:
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
Chris Johnsen
2010-09-03 04:35:14