Is it possible to force git to only merge remote tracking branches into the corresponding local branch? E.g. assume origin/X tracks X on origin and corresponds to local X and the same for origin/Y and Y. I want to prevent users to do git checkout Y; git merge origin/X
. Is it possible? How?
Edit:
To make it clear: The workflow is not the problem. People try to merge the wrong branches because they forgot to checkout the correct branch before merging. It is not about "offenders" or pushing to the central repo. It's just people forgetting at which branch they are. The last "incident" was literally:
"I should commit and push real quick before I leave.
git add .
git commit -am 'Feature Y'
git push originWhoops, whats that. It tells me to merge branch origin/X first. OK whatevs.
git merge origin/X
Whoops, whats that now. Lots of merge conflicts. What have I done. I better call somebody..."
The user was working in branch Y and did not understand what the git push origin
was saying. It told it that origin/X needed merging and that's what he did, because he wanted to "push real quick". In the case above branch X was one commit ahead of the local X, so pushing all branches yielded the "needs merging" error.
I adjusted the "workflow" now to always push a branch explicitly, e.g. git push origin Y
instead of just git push origin
, but that's not curing the problem. It should (usually) not be allowed without a warning to merge origin/X with Y. For merging feature branches X and Y can be merged.