I'm starting to play around with git hooks, and I'd like to create one to prevent a developer from creating a new branch when on a specific branch. The current process in our company is meant to look like this:
git checkout master
git fetch
git reset --hard origin/master
git checkout -b [branch name]
do awesome things.
However, occasionally when moving quickly, some developers end up starting this new branch from a staging repo. Which causes grief.
So, I'd like to create a hook to interrupt when a developer starts to create a new branch, check what branch they're on, and either exit 1
if the branch is not master
(or just generally stop the action if the branch name is staging
), or allow it otherwise.
Edit:
As I search more on this, I realize I want a pre-checkout hook, which doesn't appear to exist. Unless someone has a better idea, I'll proceed to print a very large warning in a post-checkout hook if the above scenario comes to pass.