Skip to content

Instantly share code, notes, and snippets.

@gotpop
Last active September 29, 2017 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotpop/ef00f4b4cdfaf75abdfcd3c2819ffe16 to your computer and use it in GitHub Desktop.
Save gotpop/ef00f4b4cdfaf75abdfcd3c2819ffe16 to your computer and use it in GitHub Desktop.
Modify the variable to change the protected git branch

Protect a branch from commits

Modify the variable to change the protected git branch. Drop pre-commit into .git/hooks to use.

#!/bin/bash
protected_branch='develop'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to commit to develop, is that really a world that you want to live in? [y|n] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
echo "You just committed to develop!"
exit 0 # push will execute
fi
echo "You didn't commit to develop - phew!"
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