Last active
April 11, 2024 17:39
-
-
Save andrewsouthard/a3f3cc7604f4afb0f65a66344e998813 to your computer and use it in GitHub Desktop.
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 | |
| # If you forget to checkout a branch, you can use a pre-push hook to stop you before pushing to main | |
| # Put this at ~/.git-templates/hooks/pre-push | |
| PROTECTED_BRANCH=('main' 'master') | |
| CURRENT_BRANCH=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
| if [[ " ${PROTECTED_BRANCH[@]} " == *" ${CURRENT_BRANCH} "* ]]; then | |
| read -p "You're about to push to ${CURRENT_BRANCH}, is that what you intended? [y|n] " -n 1 -r < /dev/tty | |
| echo | |
| if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
| then | |
| exit 0 # push will execute | |
| fi | |
| exit 1 # push will not execute | |
| else | |
| exit 0 # push will execute | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment