简体   繁体   中英

Does git force a local update/merge when pushing to master origin?

Say there are 100 developers working on the same project.

When each developer pushes their changeset to the central repo (origin master), are they forced to pull/merge locally to get all the updates before pushing?

Or as long as they all worked on different files and a merge isn't required, they won't be forced to do so?

Push does not do an automatic pull. If many developers are working on a single updated branch, it's advisable for them to always do

git pull --rebase && git push

The scenario you describe is not allowed: git remote repositories do not allow pushes to branches when these are not fast forwards .

Say you want to push to branch b . Remote is at point r . Your dev wants to push commits from his branch b to the remote b starting from point d up to its HEAD: this will not work if r is not strictly equal to d .

This is by design: if you were allowed to do this, you'd break every other developers' branches who work on the project, not to mention the very high chance of losing commits. Devs have their local reflogs, sure, but still.

Short answer: yes, they will have to have fetched and merged in any other changes on the branch they are pushing to.

Longer answer: Git purposefully does not try to be smart as to whether changes need merging into one another: as far as Git is concerned, the history has changed, so the tree will need merging client-side. Thankfully, in most cases this is as simple as a git pull or a git pull --rebase , followed by a quick check on what the changes were and whether everything still works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM