Skip to content

Instantly share code, notes, and snippets.

View andrewsouthard's full-sized avatar

Andrew Southard andrewsouthard

View GitHub Profile
#!/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