Skip to content

Instantly share code, notes, and snippets.

@wx257osn2
Last active October 9, 2017 05:17
Show Gist options
  • Save wx257osn2/3c9cd405113fc5d0d4d5d29dfcc9f83e to your computer and use it in GitHub Desktop.
Save wx257osn2/3c9cd405113fc5d0d4d5d29dfcc9f83e to your computer and use it in GitHub Desktop.
Warning script about commit to master branch(git pre-commit hook)
#!/bin/sh
mkdir -p ~/.git_template/hooks
git config --global init.templatedir ~/.git_template
cat pre-commit >> ~/.git_template/hooks/pre-commit
chmod +x ~/.git_template/hooks/pre-commit
#!/bin/sh
MASTER='master'
yasuno () {
printf "\e[33;1m${1} \e[37;1m[y/N]: \e[m"
exec < /dev/tty
read yn
case $yn in
[yY]*) return 0 ;;
*) return 1 ;;
esac
}
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
if test $CURRENT_BRANCH = $MASTER; then
yasuno "WARNING: You are on the '$MASTER' branch now.\nDo you REALLY want to commit to the $MASTER branch?"
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment