62

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?

HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
Hilbert-
  • 623
  • 1
  • 5
  • 4

5 Answers5

67

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.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • 4
    Will it work if the current and remote branches have same name but different case? e.g "AppName" vs "appname", just curious.. – Prince Apr 14 '14 at 19:47
37
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

Andrew C
  • 13,845
  • 6
  • 50
  • 57
bluesman
  • 2,242
  • 2
  • 25
  • 35
  • 9
    A slight clarification to that - `git push origin` may by default push all branches, but really it pushes "whatever you have configured to push". The default can be changed, so unless you know what your repo is configured to push, the explicit `git push origin master` is "safer" in some respect. – twalberg Sep 17 '12 at 15:46
  • 1
    See the accepted answer for a clarification on a change since version 1.7.11 – Dercsár Mar 13 '13 at 09:45
1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0
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.

Avnish Jayaswal
  • 161
  • 1
  • 4
0

git push origin main vs master

[

refer to documentation on github

]2

Ndiklas
  • 77
  • 1
  • 6