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.
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.
-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.
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.
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..
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With