Skip to content

Instantly share code, notes, and snippets.

@chriscarrollsmith
Created July 1, 2025 20:19
Show Gist options
  • Save chriscarrollsmith/91edc26d3ef2c2ff8cfbb1124a7845d0 to your computer and use it in GitHub Desktop.
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
#!/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