Last active
March 17, 2023 01:51
-
-
Save bricss/603bfcaf1291cfa7a20a5d6f2eece3fd to your computer and use it in GitHub Desktop.
Warns before pushing to protected branches
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
| #!/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