Our team uses a release branching strategy. A week before each release, we will create a branch off of master, e.g. "Release_1.2.3". We send this branch to our quality engineers for verification, and use the week prior to the release to merge in critical bug fixes before releasing our software to our users. During this time, feature development continues on master. Once Release 1.2.3 is officially released, we merge Release_1.2.3 back into master.
This approach generally works for us, except for one flaw: When working on changes targeting Release_1.2.3, some devs have incorrectly merged master into their development branch and then manually deleted the unnecessary changes. This causes issues when merging Release_1.2.3 back into master, since git views the deletions made as being a part of the history, and will try to make the same deletions on master.
We've tried to educate devs about this issue, but we have a large team contributing to the codebase (including many devs without much experience in git). Instead, I'm looking for an automated way to prevent these sorts of harmful merges. We use Github's Branch Protection Rules to prevent direct commits to master; can we use a similar approach here?
Alternatively, is there a programmatic way of detecting that a branch contains a harmful merge? We could potentially incorporate that into our existing CI system.