4

We at work have three branches

  • master
  • release
  • develop

We develop into branches based on the develop one, when finished, we merge that develop into the release one for the application to be tested. Meanwhile, we keep developing and merging things in develop.

One's release is tested, we make a merge into master. We never should merge develop directly into master and we want to avoid human factor accidents automatically.

Is there a git way to make branches incompatibles so any attempt to merge one into another is rejected? Is there a plugin or something?

4
  • My first thought was "git hooks", but, apparently, there isn't a "pre-merge" hook. Second thought: maybe you shouldn't fight the convention? master is a "special" branch name. It's a default target branch for Pull Requests, etc. One could say, branches are meant to be merged to master. Commented Apr 3, 2017 at 14:37
  • As for the actual question, even if you're not successful in preventing such merges, I'm sure that it's possible to detect them after the fact (and undo manually, or something). Commented Apr 3, 2017 at 14:38
  • "One's release is tested, we make a merge into master" --> everywhere i've seen it's the other way around... test in master and then make a release Commented Apr 3, 2017 at 14:40
  • May be useful: stackoverflow.com/questions/21623699/… Commented Apr 3, 2017 at 14:42

1 Answer 1

4

Your best bet to really enforce this is to install a pre-receive hook on the receiving end (i.e., in your central "push" repository).

As per https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks :

The first script to run when handling a push from a client is pre-receive. It takes a list of references that are being pushed from stdin; if it exits non-zero, none of them are accepted. You can use this hook to do things like make sure none of the updated references are non-fast-forwards, or to do access control for all the refs and files they’re modifying with the push.

Check the documentation and the example hooks in .git/hooks/*.sample, you should be able to put something together (i.e., go through the references you got as command line parameters, check whether each of them contains one of your invalid merges, and exit 1 if it did). Let us know if you can't seem to get it to work.

To find out whether you want to accept the merge, you can get creative with git log.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.