Last active
August 15, 2021 19:38
-
-
Save nanotaboada/7e23364b51485c16e041 to your computer and use it in GitHub Desktop.
Git pre-push hook that prevents pushing directly to master branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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