Skip to content

Instantly share code, notes, and snippets.

@nanotaboada
Last active August 15, 2021 19:38
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 nanotaboada/7e23364b51485c16e041 to your computer and use it in GitHub Desktop.
Save nanotaboada/7e23364b51485c16e041 to your computer and use it in GitHub Desktop.
Git pre-push hook that prevents pushing directly to master branch
#!/bin/sh
# ---------------------------------------------------------------------------- #
# Filename: .git/hooks/pre-push #
# Description: Git pre-push hook that prevents pushing directly to master #
# branch #
# Created by: Nano Taboada <nanotaboada@msn.com> #
# Version: 0.1.0 #
# License: http://opensource.org/licenses/MIT #
# Last updated: Jun 30, 2015 #
# ---------------------------------------------------------------------------- #
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "${BRANCH}" == "master" ]; then
echo >&2 "[ERROR] Invalid operation! Cannot push directly to "${BRANCH}"."
echo >&2 "[ERROR] Please create a Pull Request instead. If you need help visit:"
echo >&2 "[ERROR] https://www.atlassian.com/git/tutorials/making-a-pull-request"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment