Created
December 1, 2020 15:05
-
-
Save nuxlli/79d25a4c4d7787bf54618823955d7732 to your computer and use it in GitHub Desktop.
A protection to not push code for main by accident
This file contains hidden or 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 | |
# Warn before pushing to protected branches | |
# - Make script executable with | |
# chmod +x pre-push | |
# - Bypass with: | |
# git push --no-verify | |
# - To add hooks on global configuration | |
# git config --global core.hooksPath [path for folder with hooks] | |
# References: | |
# - http://hammad.ca/blog/2015/03/08/confirm-before-pushing-to-master-branch | |
# - https://eidson.info/post/global-hooks-with-git | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
PROTECTED_BRANCHES="^(master|main)" | |
if [[ "$BRANCH" =~ $PROTECTED_BRANCHES ]]; then | |
read -p "Are you sure you want to push to \"$BRANCH\" ? (y/n): " -n 1 -r < /dev/tty | |
echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
exit 0 | |
fi | |
echo "Push aborted." | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment