As a one liner: git diff @{u}...
The upstream of a branch is composed of two parts, both of which can be set and retrieved with git config
. The remote part is easy, as given a branch named B
, it's branch.B.remote
. The second half is much harder if you use git config
.1 Fortunately, since about Git version 1.8 or so, the @{upstream}
suffix works for all things that parse branch names:
foo@{upstream}
is the upstream of branch foo
. @{u}
is shorthand for @{upstream}
, and standalone, means HEAD@{upstream}
.
To get the symbolic name of the upstream, if that's what you need, use git rev-parse --symbolic-full-name
or git rev-parse --abbrev-ref
. Note that if there is no upstream set for the current or given branch, you'll get an error from git rev-parse
.
1It's branch.B.merge
, but this must be run through the fetch =
mappings for the given remote to find the right remote-tracking name. That is, suppose that branch br
has branch.br.remote = r
and branch.br.merge = xyz
. You must then run refs/heads/xyz
through the remote.r.fetch
rules to come up with the remote-tracking name corresponding to xyz
on remote r
. There's no command-line command that will do this for you.