LifeOfBrianOC

• •

Auto-Sign Github Desktop Commit Messages

I prefer to use Github Desktop than cli when developing code. What can i say, i’m a UI guy! Our Github organisation requires a Developer Certificate of Origin (DCO) on Pull Requests. This essentially means you must sign every commit. It can be easy to forget to do this (and a PITA the remediate that usually involves asking my buddy Ryan Johnson to help with 🙂 ) so I wanted to find a way of auto-signing commits when using Github Desktop. The instructions below are for Mac but should be adaptable to Windows.

First, install GPG-Suite to enable creation of a GPG key.

 brew install --cask gpg-suite
# Create the auto-sign file
mkdir -p ~/.git-hooks
vi ~/.git-hooks/prepare-commit-msg
#!/bin/sh
SOB="Signed-off-by: $(git config user.name) <$(git config user.email)>"
if ! grep -q "$SOB "$1"; then
echo "$SOB" >> "$1"
fi

To enable for all repos

 chmod +x ~/.git-hooks/prepare-commit-msg
git config --global core.hooksPath ~/.git-hooks

Happy coding!