Skip to content

Instantly share code, notes, and snippets.

@jason-feng
Created May 8, 2017 20:02
Show Gist options
  • Select an option

  • Save jason-feng/ae866a63f088cd4a03ef7a14136c6c6a to your computer and use it in GitHub Desktop.

Select an option

Save jason-feng/ae866a63f088cd4a03ef7a14136c6c6a to your computer and use it in GitHub Desktop.
Prevent pushing to master
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, 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
# Credit to https://dev.ghost.org/prevent-master-push/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment