To use this hook:
- add the
prepare-commit-msg
file at.git/hooks/prepare-commit-msg
and edit as needed - make it executable:
chmod +x .git/hooks/prepare-commit-msg
- disable fast-forward merges:
git config branch.master.mergeoptions "--no-ff"
- that's it!
NOTE: after a failed merge from a forbidden branch, the working tree will still be in a MERGING state. To discard the local working copy state, run:
git reset --merge
If you are interested, I wrote the same in Bash, as sayd.
My purpose was different: avoid merge from remote branches other than master to master, so the logic is a bit different.
https://gist.github.com/hujuice/9ff2fd4221e2135f946931dbb512bfc6#file-prepare-commit-msg
Note that I've found three types of MERGE_MSG.
What I hate and I cannot resolve is the suggestion provided by git at the end: git encourages to perform the commit.
Git says «Not committing merge; use 'git commit' to complete the merge.» as very last line. Git has the last world, grrr.
Do you have ideas about?