K
K
krll-k2014-08-07 16:51:37
git
krll-k, 2014-08-07 16:51:37

What is the difference between git push -u origin master and git push origin master? Why the -u switch for the git push command?

The question is essentially to the -u switch for the git push command:

-u, --set-upstream
           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.<name>.merge in git-config(1).

What I want to get an explanation: in what cases is the -u switch necessary?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EXL, 2014-08-07
@krll-k

In case the master branch (or branch_name) is not a tracked branch origin/master (or origin/branch_name) and you want to make it so.
By executing the git push -u origin master command , you establish a link between the branch you are on and the master branch on the remote server. The command needs to be executed once, so that later you can send / receive changes only by performing git push from the branch without specifying any aliases for the server and remote branches. This is for convenience.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question