Do you always need the '-u' in git push -u origin master?
You have seen this command in many tutorials. Maybe you use it everyday, or every time you push:
This pushes changes in your local repository up to the master
branch of the remote repository origin
.
But do you need to do this every time you push?
The -u
in this command is a short-hand for --set-upstream
. Using this flag you are basically telling git to automatically link your local master to the remote master. Therefore you only need to do this once. After that you can just write git pull
and git push
on master.
Just remember to do this the first time you create a branch locally and are ready to push it to the remote:
This creates a branch called bugFix
on your remote and sets your local bugFix
branch to track it. So from now on, when you switch to that branch locally, you can just pull and push without any further argument or flag.
Pro tip:
If you want to see how your local branches are connected to remote branches, take a look at your repository’s config file. The -u
flag sets the merge property of the branch: