8

I would like to create a "pre-branch" hook that blocks users from creating a branch with a name that matches a given regex expression if another branch already exists with a name that matches that same expression.

Optimally, this could be hosted locally and trigger before the user ever touches the remote repo, but I am open to any method that would prevent a branch with the undesired name from being created on the remote (pre-push or pre-receive hooks maybe?)

Just moving over to git, so please treat my knowledge of git hooks as extremely novice.

Thanks!

1 Answer 1

5

Doing that locally isn't advisable - what a developer does in his own repo is purely his own business.

You can install a server-side hook that checks the reference's names that are being pushed. The first script in this example shows how to get the reference name.

If the developer wants to use any name, he can do it - and then, if it tries to push a bad name, he can still change that to any other name he wants using the git push <remote> <localref>:<remoteref> notation, as in git push origin badly_named:ok_named.

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

3 Comments

Thanks for the response! Before I go ahead and implement it this way, I just want to run the actual issue by you to see if you have any ideas. The specific problem is with release branches containing changes not being brought back into our development branch. The initial thought was that we could create a hook that would trigger when creating a branch whose name is similar to another remote branch. This way, we just need to require that release branches use the same naming style, and then the dev will be forced to delete the branch, prompting him to merge in any changes.
Another thought was to have a perpetual release branch. The downside being that our release branch could contain code not present in our dev branch. Thoughts?
You may have already seen it but it's so good you never overlook it: nvie.com/posts/a-successful-git-branching-model

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.