Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active March 17, 2023 01:51
Show Gist options
  • Select an option

  • Save bricss/603bfcaf1291cfa7a20a5d6f2eece3fd to your computer and use it in GitHub Desktop.

Select an option

Save bricss/603bfcaf1291cfa7a20a5d6f2eece3fd 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`
countdown=15
current=$(git rev-parse --abbrev-ref HEAD)
protect='^(main|master|release|patch-*)'
status=0
if [[ "$current" =~ $protect ]]; then
echo "You're about to push into '$current' and have $countdown seconds to abort operation."
while [[ $countdown -gt 0 ]]; do
echo $((countdown--))
sleep 1
done
fi
exit $status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment