What Is the Difference Between Git Push Origin and Git Push Origin Master

Is there any difference in pushing the master branch of a local git repository to the master branch of a remote repository called origin with git push origin master or with git push origin?

5 Answers

The default action of git push and git push origin has changed since git version 1.7.11:

  • Before 1.7.11, git push by default pushes all branches that also exist remotely with the same name.

  • Since 1.7.11, git push by default pushes the current branch to a remote branch with the same name.

Before and after version 1.7.11, the default behavior can be configured with the push.default configuration option. This configuration option has been introduced in git version 1.6.3.

1
git push origin master

This only pushes your master branch to origin

git push origin

Pushes all your branches to origin

UPDATE - The behavior of Git has changed since this answer was written. git push origin on Git >=2.0 by default pushes the current branch to a matching branch of the same name, but this behavior can be overridden via git config

2

While git push origin on Git >=2.0 does indeed by default push the current branch to a matching branch of the same name, the documentation is wrong!
Said documentation is fixed with Git 2.32 (Q2 2021, 8 years later):

See commit 4c8e3dc (08 Mar 2021) by Taylor Blau (ttaylorr).
(Merged by Junio C Hamano -- gitster -- in commit c6617d1, 24 Mar 2021)

Documentation/git-push.txt: correct configuration typo

Reported-by: Adam Sharafeddine
Reported-by: Fabien Terrani
Signed-off-by: Taylor Blau
Reviewed-by: Jonathan Nieder

In the EXAMPLES section, git-push says that 'git push origin'(man) pushes the current branch to the value of the 'remote.origin.merge' configuration.

This wording (which dates back to b2ed944 (push: switch default from , 2013-01-04, Git v2.0.0-rc0 -- merge) (push: switch default from "matching" to "simple", 2013-01-04)) is incorrect.
There is no such configuration as 'remote.<name>.merge'.
This likely was originally intended to read "branch.<name>.merge" instead.

Indeed, when 'push.default' is 'simple' (which is the default value, and is applicable in this scenario per "without additional configuration"), setup_push_upstream() dies if the branch's local name does not match 'branch.<name>.merge'.

Correct this long-standing typo to resolve some recent confusion on the intended behavior of this example.

git push now includes in its man page:

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.