It will check if current branch is master or a release branch and, if so, prevents a commit or push
-
Enable git templates
git config --global init.templatedir '~/.git-templates'
-
Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
-
Copy the
pre-commit
andpre-push
hooks below to~/.git-templates/hooks
-
Make them executable
chmod a+x ~/.git-templates/hooks/pre-commit chmod a+x ~/.git-templates/hooks/pre-push
-
Re-initialize git in your cloned projects to enable these scripts there:
cd <your-git-clone-folder> git init
After this you should see an error if you try to commit to the master or a releaseXXX branch:
$ git commit -m "test commit to master branch"
You can't commit directly to master branch