Created
August 14, 2023 21:03
-
-
Save iul1an/6455b02e7c12affd43adc8980e9a512e to your computer and use it in GitHub Desktop.
git pre-push hook: do not allow push 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 | |
# The remote repo | |
remote="$1" | |
url="$2" | |
# Check each commit that's being pushed | |
while read local_ref local_sha remote_ref remote_sha | |
do | |
if [ "$remote_ref" = "refs/heads/master" ]; then | |
echo "Error: You're attempting to push to the remote master branch. This is not allowed!" | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
save it as .git/hooks/pre-push and make the file executable