Last active
March 17, 2023 01:49
-
-
Save bricss/f7327aa3c3bd09360ada37c6ce1b6e32 to your computer and use it in GitHub Desktop.
Warns before pushing to protected branches
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
#!/usr/bin/env bash | |
# Warns before pushing to protected branches | |
# Bypass with `git push --no-verify` | |
current=$(git rev-parse --abbrev-ref HEAD) | |
protect='^(main|master|release|patch-*)' | |
status=0 | |
if [[ "$current" =~ $protect ]]; then | |
while true; do | |
read -p "Push to '$current' branch? [Yy|Nn]: " input | |
case "$input" in | |
[Yy] ) status=0; break;; | |
[Nn] ) status=1; break;; | |
* ) echo 'Please answer: [Yy|Nn]';; | |
esac | |
done | |
fi | |
exit $status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment