Skip to content

Instantly share code, notes, and snippets.

@rmela
Last active December 9, 2019 17:19
Show Gist options
  • Save rmela/07da54ef690ea3c6a167c2b27b811514 to your computer and use it in GitHub Desktop.
Save rmela/07da54ef690ea3c6a167c2b27b811514 to your computer and use it in GitHub Desktop.
Git hook to prevent pushing to master or release
!/bin/bash
#
# Put this script into ~/.githooks/pre-push and make it executable.
# Then run git config -add core.githooks ~/.gitconfig
#
# You could also put it into .git/hooks for a particular repo
# and skip the git config step
#
REGEX='s/.*\/\(.*\)/\1/'
SCRIPT=$(dirname $0)/$0
CURRENT_BRANCH=$(git symbolic-ref HEAD | sed -e $REGEX )
if [ $CURRENT_BRANCH = master ] || [ $CURRENT_BRANCH = release ] ## >> Test << || [ $CURRENT_BRANCH = pre-push-test-branch ]
then
echo Push to $CURRENT_BRANCH not allowed git hook $SCRIPT
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment