Skip to content

Instantly share code, notes, and snippets.

@nix1947
Created February 3, 2017 09:59
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 nix1947/c5e201ed99cb54db768eef19a9367e96 to your computer and use it in GitHub Desktop.
Save nix1947/c5e201ed99cb54db768eef19a9367e96 to your computer and use it in GitHub Desktop.
prevent accidental push to master branch while using git
#!/bin/bash
# save this script to .git/hooks/pre-push
# Change the permission as chmod +x .git/hooks/pre-push
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment