Git Question

What does '--set-upstream' do?

What does

do? I tried to understand it by reading manual, but I didn't quite get it. Can you explain it to me?

Answer Source

git branch --set-upstream <remote-branch>
sets the default remote branch for the current local branch.

Any future 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 do --set-upstream is
to use the shorthand flag -u along-with the very first git push 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 git deprecate this somewhat ambiguous --set-upstream option in favor of a more verbose --set-upstream-tooption with identical syntax and behavior

git branch --set-upstream-to <remote-branch>