Last active
December 9, 2019 17:19
-
-
Save rmela/07da54ef690ea3c6a167c2b27b811514 to your computer and use it in GitHub Desktop.
Git hook to prevent pushing to master or release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/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