Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

Why is pushing to matching the default in 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...