What does '--set-upstream' do?
git branch --set-upstream <remote-branch>
sets the default remote branch for the current local branch.
git pull command (with the current local branch checked-out),
will attempt to bring in commits from the
<remote-branch> into the current local branch.
One way to avoid having to explicitly type
--set-upstream is to use its shorthand flag
-u as follows:
git push -u origin local-branch
This sets the upstream association for any future push/pull attempts automatically.
For more details, checkout this detailed explanation about upstream branches and tracking.
To avoid confusion, recent versions of
gitdeprecate this somewhat ambiguous
--set-upstreamoption in favour of a more verbose
--set-upstream-tooption with identical syntax and behaviour
git branch --set-upstream-to <origin/remote-branch>
Read more... Read less...
When you push to a remote and you use the
--set-upstream flag git sets the branch you are pushing to as the remote tracking branch of the branch you are pushing.
Adding a remote tracking branch means that git then knows what you want to do when you
git pull or
git push in future. It assumes that you want to keep the local branch and the remote branch it is tracking in sync and does the appropriate thing to achieve this.
You could achieve the same thing with
git branch --set-upstream-to or
git checkout --track. See the git help pages on tracking branches for more information.
git branch --set-upstream <<origin/branch>> is officially not supported anymore and is replaced by
git branch --set-upstream-to <<origin/branch>>