It will check if current branch is master, then ask a confirmation, in case of master
branch
Articles with initial info: https://dev.ghost.org/prevent-master-push/, https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook
- Enable git templates
git config --global init.templatedir '~/.git-templates'
- Create a directory to hold the global hooks:
mkdir -p ~/.git-templates/hooks
- Write your hook in ~/.git-templates/hooks
See file pre-push
in this gist.
Copy it to ~/.git-templates/hooks/pre-push
- Make it executable
chmod a+x ~/.git-templates/hooks/pre-push
- In currently existing project, do reinit
git init
This will not overwrite existing commits, or existing hooks.
Done!
I added a few messages to indicate the status better, can someone help out with making the protected_branch an array and checking if we are pushing into any one of them