Skip to content

Instantly share code, notes, and snippets.

@reubenmiller
Last active March 24, 2023 13:30
Show Gist options
  • Save reubenmiller/a4720fac720d7cfd2d322402b44c26f1 to your computer and use it in GitHub Desktop.
Save reubenmiller/a4720fac720d7cfd2d322402b44c26f1 to your computer and use it in GitHub Desktop.
Add signedoff-by message to all git commits via a git hook

Getting started

Add the following signedoff-by git hook using the following steps:

  1. Create a new file (from above) and add it to the project's git folder .git/hooks/commit-msg
  2. Make the hook executable
chmod +x .git/hooks/commit-msg
#!/bin/sh
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