Skip to content

Instantly share code, notes, and snippets.

@thibaut-pro
Created February 21, 2020 16:55
Show Gist options
  • Save thibaut-pro/eea5d1e4ee2307aa313f6b4193755a95 to your computer and use it in GitHub Desktop.
Save thibaut-pro/eea5d1e4ee2307aa313f6b4193755a95 to your computer and use it in GitHub Desktop.
Git prehook to protect staging and master branches
#!/bin/sh
# To bypass this hook and force the push, use 'git push --no-verify'
protected_branches=('staging' 'master')
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
for branch in "${protected_branches[@]}"
do
if [ $branch = $current_branch ]; then
echo "You're about to push $branch and you don't want that"
exit 1
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment