Skip to content

Instantly share code, notes, and snippets.

@palkx
Last active October 14, 2019 11:40
Show Gist options
  • Save palkx/c8a5d0685e03fc70499b769b36d549de to your computer and use it in GitHub Desktop.
Save palkx/c8a5d0685e03fc70499b769b36d549de to your computer and use it in GitHub Desktop.
Git global sign-off hook

Add global hooks dir

git config --global core.hooksPath /path/to/my/centralized/hooks

Add commit-msg hook

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

make it executable

chmod +x commit-msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment