Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is pushing to matching the default in Git?

Tags:

git

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?

like image 867
Casebash Avatar asked Feb 14 '14 06:02

Casebash


1 Answers

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.

like image 166
VonC Avatar answered Sep 22 '22 23:09

VonC