Created
September 6, 2025 17:57
-
-
Save ergosteur/c7b1b0cbf0534c96988f533b450122fe to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| # setup-git-email-enforcer.sh | |
| # This script enforces using the GitHub anon email for all commits. | |
| GOOD_EMAIL="[email protected]" | |
| HOOKS_DIR="$HOME/.git-hooks" | |
| HOOK_FILE="$HOOKS_DIR/commit-msg" | |
| # Create hooks dir if it doesn't exist | |
| mkdir -p "$HOOKS_DIR" | |
| # Write the hook | |
| cat > "$HOOK_FILE" <<EOF | |
| #!/bin/sh | |
| EMAIL="\$(git config user.email)" | |
| GOOD="$GOOD_EMAIL" | |
| if [ "\$EMAIL" != "\$GOOD" ]; then | |
| echo "Wrong Git email (\$EMAIL). Expected \$GOOD" | |
| exit 1 | |
| fi | |
| EOF | |
| # Make it executable | |
| chmod +x "$HOOK_FILE" | |
| # Point Git to use this hooks path globally | |
| git config --global core.hooksPath "$HOOKS_DIR" | |
| echo "Global Git hook installed. All commits must use: $GOOD_EMAIL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment