Skip to content

Instantly share code, notes, and snippets.

@Tymek
Created May 12, 2025 11:37
Show Gist options
  • Save Tymek/8657a01c9420eccc4fdeb5b1a851f68d to your computer and use it in GitHub Desktop.
Save Tymek/8657a01c9420eccc4fdeb5b1a851f68d to your computer and use it in GitHub Desktop.
prevent accidental commits
echo '#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" = "main" ]; then
echo "Main Branch commit is blocked"
exit 1
fi
' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment