What's the use of `-u` in `git push -u origin master`? [duplicate]
Possible Duplicate开发者_StackOverflow中文版:
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.
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
.
精彩评论