12

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?

umläute
  • 28,885
  • 9
  • 68
  • 122
Reshad
  • 2,570
  • 8
  • 45
  • 86
  • 3
    What do you mean, it "sends it 2x" to the upstream? What are you seeing? – Thomas Stringer Sep 11 '15 at 13:43
  • Possible duplicate of [What is the difference between git push origin and git push origin master](https://stackoverflow.com/questions/12462481/what-is-the-difference-between-git-push-origin-and-git-push-origin-master) – tidy May 17 '19 at 08:37

1 Answers1

8

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)
Thomas Stringer
  • 5,682
  • 3
  • 24
  • 40