Skip to content

Instantly share code, notes, and snippets.

@usmansaleem
Last active December 3, 2021 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usmansaleem/68d77bd7ae2c832791d6290df47bdbb3 to your computer and use it in GitHub Desktop.
Save usmansaleem/68d77bd7ae2c832791d6290df47bdbb3 to your computer and use it in GitHub Desktop.
DCO automatic signoff git hook

https://stackoverflow.com/a/46536244/535610

Save the following as .git/hooks/prepare-commit-msg and make it executable.

#!/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