On GitHub, they advice to do git push -u origin master, instead of git push.
What is the main difference ?
From man git-push
:
-u, --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference ...
Basically, it means that it will not only upload your master
to the master
at origin
, but also set up the local copy origin/master
to be the tracking branch, that is the upstream of your local master
.
This is usually already this way, so if that is the case, being in master
and doing git push -u origin master
will do nothing different from a plain git push
. But if you misconfigured your repository, then sometimes the long version will fix it automatically.
Naturally, doing that command without thinking may result in bad situations, for example if you are in a public working branch and do that:
{mybranch} $ git push -u origin master
Now you uploaded your mybranch
as master
and set up origin/master
as the upstream of mybranch
, instead of the proper origin/mybranch
, and you created quite a mess!
My guess is that GitHub recommends that for git newbies, to avoid calls to their customer support. But I would not recommend that as a default for pushing. In fact, if you misconfigure the upstream, a plain git push
will fail with this message:
fatal: The current branch a has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
that tells you exactly what is happening and how to fix it (--set-upstream
is a synonym of -u
).