Skip to content

Instantly share code, notes, and snippets.

@archiewald
Last active March 26, 2019 20:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archiewald/64f50efa0a5c51718898f9a154a4f742 to your computer and use it in GitHub Desktop.
Save archiewald/64f50efa0a5c51718898f9a154a4f742 to your computer and use it in GitHub Desktop.
[warn pushing to protected branches] #git
!/bin/bash
protected_branches=('master' 'develop')
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
is_branch_protected=false;
for protected_branch in "${protected_branches[@]}"
do
if [ $protected_branch = $current_branch ]
then
is_branch_protected=true
fi
done
if [ $is_branch_protected = true ]
then
read -p "You're about to push ${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