What is the difference between git push origin and git push origin master
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
.
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
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 typoReported-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.