5

For the default setting, Git pushes to the 'matching' branch - the branch with the same name, rather than the 'upstream' branch - the branch being tracked. It would be more convenient for me to switch to the 'upstream' mode so that I don't have to specify each time what branch I am pushing too, but I assume 'matching' is the default for a reason. Are there any issues that having the setting as 'matching', rather than 'upstream' setting will resolve?

Casebash
  • 114,675
  • 90
  • 247
  • 350
  • 2
    Hysterical Raisins (the funny spelling for "historical reasons" that also implies: no really good reason). The default will be changed in git 2.0, so obviously the git project folks think the existing default is not the best choice. – torek Feb 14 '14 at 06:47
  • 1
    The new default is set to be `simple` for Git 2.0 (Q2 2014): see [my edited answer below](http://stackoverflow.com/a/21772695/6309) – VonC Mar 12 '14 at 15:34

1 Answers1

6

As mentioned in "Warning: push.default is unset; its implicit value is changing in Git 2.0":

matching means git push will push all your local branches to the ones with the same name on the remote. This makes it easy to accidentally push a branch you didn't intend to.

And that is not a best practice: you shouldn't push all your branches.
Most of them can be private branches for test or internal dev only.

simple (Git 2.0 default) means git push will push only the current branch to the one that git pull would pull from, and also checks that their names match.

By default, it pushes the branch you are working on, only if said branch exists on the remote side with the same name (or if you create it explicitly).

You can find more discussion about that policy change in "[git push - Default behavior?].2".

I describe the other policies in "git - push current vs. push upstream (tracking)".


That new default policy is now merged to main (commit 289ca27) and states it is the new default in commit 11037ee:

We promised to change the behavior of lazy "git push [there]" that does not say what to push on the command line from "matching" to "simple" in Git 2.0.

This finally flips that bit.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I assume that there's some reason why they make simple check that the names match, rather than just using upstream – Casebash Feb 14 '14 at 12:15
  • @Casebash mainly to force users to work with a coherent branch naming convention (ie the same on local and on remote), rather than use a name on one side and a *different* name for the upstream branch. – VonC Feb 14 '14 at 12:17