Skip to content

Instantly share code, notes, and snippets.

@fgaray
Last active April 10, 2023 17:21
Show Gist options
  • Save fgaray/c9c5a7e498a57237ff9c456824c1f145 to your computer and use it in GitHub Desktop.
Save fgaray/c9c5a7e498a57237ff9c456824c1f145 to your computer and use it in GitHub Desktop.
Git Hook: Sign-off your commits
#!/bin/sh
# File: .git/hooks/prepare-commit-msg
# Source: https://stackoverflow.com/a/46536244
NAME=$(git config user.name)
EMAIL=$(git config user.email)
if [ -z "$NAME" ]; then
echo "empty git config user.name"
exit 1
fi
if [ -z "$EMAIL" ]; then
echo "empty git config user.email"
exit 1
fi
git interpret-trailers --if-exists doNothing --trailer \
"Signed-off-by: $NAME <$EMAIL>" \
--in-place "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment