What is the difference between git push origin and git push origin master

GitGit PushGit Remote

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

Solution 3 - Git

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:

> ## git push origin: > > Without additional configuration, pushes the current branch to the configured upstream (branch.<name>.merge configuration variable) if it has the same name as the current branch, and errors out without pushing otherwise.

Solution 4 - Git

git push origin

git push origin will push changes from all local branches to matching branches the origin remote.

git push origin master

git push origin master will push changes from the local master branch to the remote master branch.

Solution 5 - Git

git push origin main vs master

[

> refer to documentation on github

]2

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHilbert-View Question on Stackoverflow
Solution 1 - GitouahView Answer on Stackoverflow
Solution 2 - GitbluesmanView Answer on Stackoverflow
Solution 3 - GitVonCView Answer on Stackoverflow
Solution 4 - GitAvnish JayaswalView Answer on Stackoverflow
Solution 5 - GitNdiklasView Answer on Stackoverflow