`git push` configurable default behavior.

Git

For some time now GiT has had the ability to configure the default behavior when executing a git push command. As of at least 2.18.x GiT will nag you about what you want the default behavior to be if not set.

$ git push origin
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use git push origin HEAD:master

To push to the branch of the same name on the remote, use

git push origin working_branch

To choose either option permanently, see push.default in 'git help config'.

So I did some digging around to see what the options are with the 2.18.x release. Turns out the options cover almost every use case:

  • nothing: do not push anything
  • matching: push all matching branches.
    • All branches having the same name in both ends are considered to be matching.
    • This is the default in Git 1.x.
  • upstream: push the current branch to its upstream branch (tracking is a deprecated synonym for upstream)
  • current: push the current branch to a branch of the same name
  • simple: (new in Git 1.7.11) like upstream, but refuses to push if the upstream branch’s name is different from the local one.
    • This is the safest option and is well-suited for beginners.
    • This will become the default in Git 2.0.

Source: https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified

Even thought simple will be the default in the 2.x release; I prefer current. It has served me well the last week or so.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.