Skip to content

Instantly share code, notes, and snippets.

@endymion1818
Created October 4, 2019 09:28
Show Gist options
  • Save endymion1818/7255ee12bd014dbd14e1b0040ed99ea4 to your computer and use it in GitHub Desktop.
Save endymion1818/7255ee12bd014dbd14e1b0040ed99ea4 to your computer and use it in GitHub Desktop.
protected branches (git hook)
#!/bin/bash
protected_branches=( production master )
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
for i in "${protected_branches[@]}"
do
protected_branch=$i
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push a protected 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
@endymion1818
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment