Reputation: 452
Is it possible to disable possibility to merge one branch into another? For example, I have a branch named develop
and feature branches named A
, B
and C
.
I want to make impossible to merge develop into A, or into B or into C:
git checkout A
git merge develop
should return an error.
Upvotes: 0
Views: 112
Reputation: 60245
With one obvious proviso, yes, you certainly can do this. It's not hard.
The obvious proviso: you can't stop the administrator of a repo doing whatever they want in it. If I clone your repo, it's my clone and I can do what I want in it. But you can vet anything I push.
You do have to implement some precise meaning of "make impossible to merge develop into A, or into B or into C", this looks good enough I'm just going to show the update hook for it without further comment:
#!/bin/bash
# update hook to prevent pushes updating A, B or C including merges from develop
read ref old new <<<$*
case ${ref#refs/heads/} in
A | B | C )
if [[ `git merge-base develop $ref` != `git merge-base develop $new` ]]
then { echo cannot merge develop into ${ref#refs/heads/}; exit 1; }
fi ;;
esac
and you're done. No merge of histories, no matter what anybody calls them, that include history from the develop branch, will be accepted to branch A
.
If you want to warn yourself against doing such merges in your own repos, you can check MERGE_HEAD
in your (edit: pre-merge-commit
and) pre-commit
hook and error out.
Upvotes: 3
Reputation: 239230
No, this is not possible in Git. Instead you would manually review suggested changes to your repo and reject those that you don't like (for example, somebody dragged changes from develop
to branch A
).
Upvotes: 2