2

I can ask for differences since I started on a feature branch:

git diff upstream-branch...

But it requires that I know what the upstream branch is. Is there a reference for the upstream branch, whatever it may be without me knowing before hand or having to dig for it? Like, I don't know:

git diff UPSTREAM...
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Not reading [docs](https://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltbranchnamegtupstreamemegemmasterupstreamememuem), yeah? :-( – phd May 24 '21 at 22:41
  • 1
    i am not willing to read every git doc out there... only as needed. And checking answers here in SO provide the answer to at least most everyday questions.... this one I think hadn't been asked before, I might be wrong, for sure, but google didn't point to anything right away. – eftshift0 May 24 '21 at 22:44

1 Answers1

5

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.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Wow.... @torek. Can I somehow give you, i don't know.... 50 points? – eftshift0 May 24 '21 at 22:37
  • @eftshift0: there are various ways to use rep points. I've never investigated them myself, and I don't really *need* any more at this point in time. :-) – torek May 25 '21 at 02:05