Skip to content

Instantly share code, notes, and snippets.

@iul1an
Created August 14, 2023 21:03
Show Gist options
  • Save iul1an/6455b02e7c12affd43adc8980e9a512e to your computer and use it in GitHub Desktop.
Save iul1an/6455b02e7c12affd43adc8980e9a512e to your computer and use it in GitHub Desktop.
git pre-push hook: do not allow push to master branch
#!/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
@iul1an
Copy link
Author

iul1an commented Aug 14, 2023

save it as .git/hooks/pre-push and make the file executable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment