Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the use of `-u` in `git push -u origin master`? [duplicate]

Tags:

git

Possible Duplicate:
What exactly does the "u" do? "git push -u origin master" vs "git push origin master"

In Github, when you created an empty repository, the instructions ask you to execute

git push -u origin master

So my question is, what's the use of -u option?

After reading the manpage I still didn't get it.

like image 521
Minqi Pan Avatar asked Sep 01 '11 13:09

Minqi Pan


People also ask

What is git push U origin master?

The git push --force -u origin command uploads content from a local repository to a remote repository. Normally, Git only allows changes to be pushed if the commit history of your local branch is up to date with the remote repository branch.

What does U mean in git push?

-u : The -u flag creates a tracking reference for every branch that you successfully push onto the remote repository. The local branch you push is automatically linked with the remote branch. This allows you to use commands such as git pull without any arguments.

Why origin is used in git push?

The origin represents a remote name where the user wants to push the changes. git push command push commits made on a local branch to a remote repository. The git push command basically takes two arguments: A remote name, for example, origin.

What does git diff origin master do?

It shows the changes between the tips of origin/HEAD and the master branches. You can achieve the same with following commands: git diff origin/HEAD master. git diff origin/HEAD..


1 Answers

git can set a particular branch in a remote repository to be the default "upstream" branch for that particular branch. For example, if you clone an existing repository, git will, by default, associate your master branch with the master branch in the origin repository, i.e. the one you're cloning from. This means that git can provide helpful defaults, such as being able to just use git pull while on master rather than having to specify a repository and a branch to fetch and merge from. It's also this association that lets git produce its helpful "Your branch is ahead of origin/master by 10 commits" messages...

However, if you haven't cloned from an exisiting repository, but you're wanting to set up a new origin remote that represents your newly created GitHub repository, you have to manually tell git to associate your master with master in the new origin repository. The -u to git push means "as well as pushing, associate my master branch with the one I'm pushing to". You only need to do this once for that association to be recorded in .git/config.

like image 91
Mark Longair Avatar answered Oct 11 '22 23:10

Mark Longair