Skip to content

Instantly share code, notes, and snippets.

@ergosteur
Created September 6, 2025 17:57
Show Gist options
  • Select an option

  • Save ergosteur/c7b1b0cbf0534c96988f533b450122fe to your computer and use it in GitHub Desktop.

Select an option

Save ergosteur/c7b1b0cbf0534c96988f533b450122fe to your computer and use it in GitHub Desktop.
#!/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