Created
July 1, 2025 20:19
-
-
Save chriscarrollsmith/91edc26d3ef2c2ff8cfbb1124a7845d0 to your computer and use it in GitHub Desktop.
pre-push git hook to only allow pulling from, not pushing to, a template remote
This file contains hidden or 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/bash | |
# Pre-push hook to prevent pushing from the template branch | |
# This allows pulling from template remote but prevents accidental pushes | |
current_branch=$(git symbolic-ref --short HEAD) | |
if [ "$current_branch" = "template" ]; then | |
echo "ERROR: Pushing from the 'template' branch is not allowed." | |
echo "This branch is reserved for pulling updates from the template repository." | |
echo "If you need to push changes, please switch to a different branch first:" | |
echo " git checkout main" | |
echo " git push" | |
exit 1 | |
fi | |
# Allow push for all other branches | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment