Setup git commit signing on macOS
A guide on how to setup git commit signing through GPG and GitHub.
- Enable commit signing by default:
git config --global commit.gpgsign true
- add
export GPG_TTY=$(tty)
to your `~/.zshrc - Run some setup:
brew install gpg2 gnupg pinentry-mac
mkdir ~/.gnupg
echo "pinentry-program $(brew --prefix)/bin/pinentry-mac" > ~/.gnupg/gpg-agent.conf
echo 'use-agent' > ~/.gnupg/gpg.conf
chmod 700 ~/.gnupg
source ~/.zshrc
git config --global gpg.program $(which gpg) - Generate a key
gpg --full-gen-key
- use "RSA (sign only)" (option
4
) - 4096 bits long
- valid forever (option
0
) - use your git user name and email
- give it a passphrase (make sure to remember this!)
- Export the key for GitHub
- Run
gpg -K --keyid-format SHORT
and copy the key id fromsec rsa4096/XXXXXXX 2025-09-08
(the id is theXXXXXXX
part) - run
gpg --armor --export <key-id> | pbcopy
(pbcopy
will place it in your clipboard) - Go to https://github.com/settings/keys and add a new GPG key
- Paste into the Key textbox
- Run
- Tell git to use your key
- run
gpg -k
- Copy the fingerprint from under the
pub
line git config --global user.signingkey <fingerprint>
- run
- Make a commit, enter the passphrase from step 4.6 and save it in your keychain.