Signing Git Commits
Contents
This post is a guide to sign Git commits.
macOS
Homebrew
Install
gnupgandpinentry-mac.1brew install gnupg pinentry-macGenerate a GPG key. You can also refer to the GitHub Docuemnt.
1gpg --full-generate-key- At the prompt, specify the kind of key you want (e.g.
RSA (sign only)). - At the prompt, specify the key size (>= 4096) you want (e.g.
4096).
- At the prompt, specify the kind of key you want (e.g.
Get the GPG key ID from the output of the following command.
1gpg --list-secret-keys --keyid-format=longExport the GPG key.
1gpg --armor --export <some GPG key ID>Add the GPG key to GitHub. You can refer to the GitHub Docuemnt.
Set
gpg-agentup.1 2echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf killall gpg-agentAdd Git configurations.
1 2git config --global gpg.program gpg git config --global commit.gpgsign trueCheck whether a commit was signed.
1git log --show-signature -1
MacPorts
Install
gnupg2with thepinentry_macvariant.1sudo port -N install gnupg2 +pinentry_macIf MacPorts reports that
pinentry-macrequires a full Xcode installation, install its prebuilt package first, then retry:1 2sudo port -N -b install pinentry-mac use_xcode=no sudo port -N install gnupg2 +pinentry_mac-ballows binary packages only;use_xcode=nobypasses the Xcode check for this installation. This requires an available prebuilt package for your macOS version and architecture. If none is available, install a compatible full Xcode to buildpinentry-macfrom source.Follow steps
2to5in the Homebrew section above to generate and add your GPG key to GitHub.Set
pinentry-programin~/.gnupg/gpg-agent.confto the MacPorts application path, replacing any existingpinentry-programline:1pinentry-program /Applications/MacPorts/pinentry-mac.app/Contents/MacOS/pinentry-macRestart
gpg-agent:1killall gpg-agentFollow steps
7and8in the Homebrew section above to configure Git and check a commit’s signature.
Ubuntu Server (22.04)
Install
gnupg.1sudo apt install gpgFollow the above steps (described for macOS) from
2to5.Set the environment variable.
1export GPG_TTY="$(tty)"Add Git configurations.
1 2git config --global gpg.program gpg git config --global commit.gpgsign trueCheck whether a commit was signed.
1git log --show-signature -1
Author Adonis Ling
LastMod 2026-11-05 (ee2ad87)