Git does not know or care how a branch name, like master
or feature-31415
or ourDevelopmentProcessUsesReallyLongBranchNamesBecauseTheyHateUs
, came about. All it knows or cares about is that the name exists and currently points to some particular commit. That said, though, every branch can have one upstream setting.
The upstream that you configure is taken as the merge argument if you run git merge
with no arguments, or to use as the <upstream>
argument for git rebase
if you run that with no arguments, and so on. Typically the upstream for master
is origin/master
. You could set sbr
(short branch) to have origin/anotherLongNameBecauseTheyWantToReplaceUsWithRobots
as its upstream, and never have to type that again.
To set origin/zorg
as the upstream for evil
:
git branch --set-upstream-to=origin/zorg evil
and to remove the upstream:
git branch --unset-upstream evil
The upstream setting is simply a two-part field:
$ git config --get branch.master.remote
origin
$ git config --get branch.master.merge
master
This is how and why master
has origin/master
as its upstream.1 The upstream is also used automatically by git status
, and is the default push target for git push
, and is the result of applying @{upstream}
to the branch name. This is all built in to Git. The catch is that you get only one upstream per branch. If that's all you need, you are good.
You can add your own configuration items, e.g.:2
$ git config branch.master.zorblax giant-space-eel
but nothing in Git itself will use this. Still, Git is a giant tool-set, not just a predigested solution that can never be used for anything outside the immediate imagination of its developers: you can write your own code that uses the zorblax
setting, if you like.
1You can set a local branch as the upstream of another local branch. Configuration-wise, this sets the remote
part to .
, which the rest of Git then ignores when necessary, e.g., for showing the @{upstream}
setting symbolically.
There is also a hidden detail here having to do with branch name mapping, when remote
is set to the name of a remote. This is because the original value of the merge
setting predates the invention of remotes. Normally this makes no difference, though.
2President Zorblax. Note date of comic, more than ten years ago. I suspect the red-button text is newer, though....