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!
Important security note -- the above will give you a false sense of security and won't work for things like
Which was, in my case, the main cause of why I pushed to
master
by accident. Fixed version of the script is below and also in my fork:(Note you'll need to
rm .git/hooks/pre-push && git init
to make the repos pick the updated version.)In any case, thanks for this -- it got me 50% of the way at least :)