Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active March 17, 2023 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricss/f7327aa3c3bd09360ada37c6ce1b6e32 to your computer and use it in GitHub Desktop.
Save bricss/f7327aa3c3bd09360ada37c6ce1b6e32 to your computer and use it in GitHub Desktop.
Warns before pushing to protected branches
#!/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