Why is pushing to matching the default in Git?

前端 未结 1 1283
逝去的感伤
逝去的感伤 2020-11-30 11:54

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 m

相关标签:
1条回答
  • 2020-11-30 12:26

    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.

    0 讨论(0)
提交回复
热议问题