Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between git push origin master and git push

Tags:

git

What is the difference between both of these commands.

git push origin master and git push

When I use the first one ( git push origin master ) it somehow sends it 2x to the upstream and with just git push it sends it 1x.

Anyone here who can explain why this occurs?

like image 540
Reshad Avatar asked Sep 11 '15 13:09

Reshad


1 Answers

By specifying $ git push with no repository parameter, by default it'll push the current branch to the tracking remote branch.

When you specify $ git push origin you are pushing explicitly your changes to the origin remote repository.

As for your question about sending it "2x" to the upstream, that shouldn't be the behavior. It'll push the changes a single time to the upstream repository.

Documentation on git-push

When you do a $ git push with no parameters, Git is actually quite verbose with the actions it'll take:

warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
like image 99
Thomas Stringer Avatar answered Oct 22 '22 08:10

Thomas Stringer