2015 update
My initial answer below is not ideal, as the upstream branch is not necessarily the branch you are clicking on. This is only the industry you are pulling from.
With Git 2.5+, the correct command is:
git for-each-ref --format="%(refname:short) %(upstream:track)" refs/heads
See more at View Unpushed Git Commits . "
(as indicated by void.pointer in the comments , upstream:track more accurate than push:track , depending on the default push policy)
Git 2.13 (Q2 2017) uses a more general ref filter API filter with a more comprehensive git for-each-ref push :
See commit 3d9e4ce , commit 949af06 , commit 56b4360 , commit 6eac70f , commit 1a34728 , commit 1a0ca5e , commit 3a42980 , commit 17938f1 , commit 3ba308c , commit a798410 , commit b180e6f , commit 01f9582 , commit bbc4949 , fbf4949 commit 42d0eb0 , commit 4f3e3b3 , commit c58f c85 (January 10, 2017) Karthik Nayak ( KarthikNayak ) .
(merged Junio ββC Hamano - gitster - into commit 93e8cd8 , February 27, 2017)
push:
The name of the local ref that represents the location @{push} for the displayed link.
Corresponds to :short :lstrip :rstrip :track and :trackshort parameters like upstream .
Produces an empty string if @{push} ref is not configured.
If lstrip=<N> ( rstrip=<N> ) is added, separate the <N> path components separated by a slash from the front (back) (for example, %(refname:lstrip=2) turns refs/tags/foo into foo and %(refname:rstrip=2) turns refs/tags/foo into refs ).
If <N> is a negative number, separate as many path components from the specified end as possible to leave the path components -<N> (for example, %(refname:lstrip=-2) turns refs/tags/foo into tags/foo and %(refname:rstrip=-1) turns refs/tags/foo into refs )
Original answer (2014)
Another way will be available with Git 1.9 / 2/0 (Q1 2014).
See commit b28061c from Ramkumar Ramachandra (artagnon) :
for-each-ref : enter %(upstream:track[short])
Introduction:
%(upstream:track) to display " [ahead M, behind N] " and%(upstream:trackshort) to display " = ", " > ", " < " or " <> " respectively (based on contrib/completion/git-prompt.sh ).
Now you can use the following for-each-ref format:
%(refname:short) %(upstream:trackshort)
to display links with brief tracking information.
Note that :track and :trackshort only work with " upstream " and fail when using anything else.