Checks if the remote branch is master
, then asks a confirmation. Based on https://gist.github.com/ColCh/9d48693276aac50cac37a9fce23f9bda, but with updated instructions for Git 2.9+ with global hooks.
Further info: https://dev.ghost.org/prevent-master-push/, https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook, https://git-scm.com/docs/githooks#_pre_push, https://stackoverflow.com/questions/22585091/git-hooks-pre-push-script-does-not-receive-input-via-stdin
-
Check your git version. 2.9 or higher is needed for configuring global git hooks.
git --version
-
Create a directory to hold the global hooks:
mkdir ~/.git-hooks-global
-
Copy the
pre-push
file from below into~/.git-hooks-global/pre-push
and make it executable:curl -o ~/.git-hooks-global/pre-push https://gist.githubusercontent.com/GUI/676bcb25389cd01d47828fddcf37e1f2/raw/3110c99b9ef17639a14a0b442d87d1db6ff7a569/pre-push && chmod +x ~/.git-hooks-global/pre-push
-
Configure the global git hooks path:
git config --global core.hooksPath ~/.git-hooks-global
Done!