I have this in a script:
git fetch origin
git pull # merge with remote tracking branch
git merge 'origin/dev'
instead of the above, I wanted to simplify it to:
git fetch origin
git merge @upstream # whatever the lingo is to refer to the upstream branch?
git merge 'origin/dev'
what is the generic way to refer to the upstream (also called remote tracking?) branch?
In your case you want the literal sequence:
git fetch origin
git merge @{upstream}
git merge origin/dev
(I took out the single quotes, as they don't really achieve anything here).
The description of @{upstream}
appears in the gitrevisions documentation, which is quite dense1 and deserves multiple re-readings over time. It is in fact a suffix you can apply to any branch name:
master@{upstream}
develop@{upstream}
and so on. When applied to HEAD
—the current branch name—in HEAD@{upstream}
, it refers to the upstream of the current branch, in the way you might expect.2 Add that together with the usual "empty string means HEAD where appropriate" rule—e.g., master..
is short for master..HEAD
—and @{upstream}
is short for HEAD@{upstream}
.
Note that name@{upstream}
fails (with an error message) if there is no upstream set for the branch. You can also use git rev-parse
on any of the things acceptable via the gitrevisions rules, to turn it into a more-basic Git expression. That's sometimes useful in complicated scripts since it allows you to find a hash ID, which you can hang on to even if the name changes as you proceed to do things to the repository.
1"Dense" in the sense of being "packed with information", rather than in the sense of "stupid"; but also "dense" in the sense of being hard to understand.
2"Might" is probably a better word than "should" as sometimes Git does things that are surprising, unless you know all kinds of details about implementation tricks inside Git.