1

If you're on a given branch, and you're tracking a specific remote branch, is there any pointer you can use to refer to the upstream branch you're tracking?

For example, if you're currently on branch feature/ABC-123, and you're tracking origin/feature/ABC-123, is there any shortcut that you can use to refer to it, so that you could do something like

git diff UPSTREAM_THINGY

rather than typing in

git diff origin/feature/ABC-123

Related question: compare local git branch with remote branch?

Community
  • 1
  • 1
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

1 Answers1

1

Yes: @{upstream}

Courtesy of this answer, the git documentation for specifying revisions has:

<branchname>@{upstream}, e.g. master@{upstream}, @{u}
The suffix @{upstream} to a branchname (short form <branchname>@{u}) refers to the branch that the branch specified by branchname is set to build on top of (configured with branch.<name>.remote and branch.<name>.merge). A missing branchname defaults to the current one.

Community
  • 1
  • 1
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
  • Incidentally `@{u}` is quite useful with `git log` as well. From my years with Mercurial I wanted the Git equivalent of `incoming` and `outgoing`, and they are: `git config --global alias.incoming 'log --oneline ..@{u}'` and `git config --global alias.outgoing 'log --oneline @{u}..'`. Since then I decided I usually want to `git log -p` incoming (no `--oneline`, with or without `-p`), so I made a shorter `lin` alias which expands to just `log ..@{u}` used as `git lin` or `git lin -p` (I don't need this for `outgoing`, I still use `git outgoing` for that). – torek Jun 16 '16 at 04:36
  • @torek sometimes I wish answers were allowable for comments. :( – Andrew Grimm Jun 16 '16 at 23:48