Search code examples
gitgit-push

Does `git push` expand to `git push origin master`?


Or does it expand to git push origin <current-branch-name>?

References


Solution

  • TL;DR

    By default, git push expands to git push origin <current-branch> since Git 2.0 or git push origin <all-matching-branches> for older versions.

    The actual answer

    The answers to all your questions regarding git push are in the documentation page of git push: http://git-scm.com/docs/git-push

    A fragment from that page (I removed the myriad of options as they are not mentioned in the question):

    git push ... [<repository>] [<refspec>]

    When the command line does not specify where to push with the <repository> argument, branch.*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin.

    When the command line does not specify what to push with <refspec>... arguments or --all, --mirror, --tags options, the command finds the default <refspec> by consulting remote.*.push configuration, and if it is not found, honors push.default configuration to decide what to push (See git-config[1] for the meaning of push.default).

    Since Git 2.0 the default value of push.default is simple which means push current branch with some checks and conditions that can make git refuse to push in some situations.

    Before Git 2.0, the default value of push.default used to be matching which means push all branches having the same name on both ends. This mode also requires some conditions to be met in order to succeed.

    For more details about push.default see the documentation page of git config or type git help config on your terminal.