What does the “-u” do in git push -u origin master?

Posted one year ago

As simply put as can be, -u specifies the “upstream”

git push -u origin master

is the same as

git push origin master; git branch --set-upstream master origin/master

If you forget the “-u” when pushing your commit perform the last command git branch—set-upstream master origin/master


Upstream refers to the main repo that people will be pulling from. So when future you runs “git push”  Git “Knows” where you want to push and pull from, meaning you can use “git push” and “git pull” without the need for any additional arguments.

Taken directly from the Git documentation

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. For more information, see branch.

.merge in git-config[1].