Skip to content

Instantly share code, notes, and snippets.

@michaelb87
Created January 23, 2024 14:31
Show Gist options
  • Save michaelb87/146e170221cc0c1dc6329693f69b81bd to your computer and use it in GitHub Desktop.
Save michaelb87/146e170221cc0c1dc6329693f69b81bd to your computer and use it in GitHub Desktop.
Place in .git/hooks/pre-commit
#!/bin/sh
# NOTE: make file executable with:
# chmod +x .git/hooks/pre-commit
# Get the current branch name
branch=$(git rev-parse --abbrev-ref HEAD)
# Check if the current branch is 'main'
if [ "$branch" = "main" ]; then
echo "You can't commit directly to main branch."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment