Configure Commit Signing on Mac with GPG
Overview
This article explains how to configure your Mac to sign Git commits with a GPG key.
All commits must be signed using either a CAC or a GPG key. Developers who do not use a CAC can configure Git to sign commits using a GPG key.
For projects operating in IL4 and IL5 environments, CAC signing is required. If you have a CAC, follow the Configure Commit Signing on Mac with Your CAC Guide instead.
WARNING
Store your GPG private key securely. Anyone with access to your private key can create signed commits that appear to come from you.
WARNING
Party Bus does not support commit signing through IDE integrations. If you create commits in an IDE, use the command line to sign them. Do not submit Party Bus support requests for IDE-specific commit signing issues.
Prerequisites
Before you begin:
Install Git.
Install Homebrew, if it is not already installed.
Install GnuPG.
bashbrew install gpgVerify the installation.
bashgpg --version git --version
Generate a GPG Key
Generate a new GPG key.
bashgpg --full-gen-keyWhen prompted:
- Select
RSA and RSAwhen prompted for the key type. - Choose an appropriate key size (4096 bits recommended).
- Specify an expiration date if required.
- Enter your name and Git email address.
- Protect the key with a strong passphrase.
Identify Your GPG Signing Key
List your secret keys.
bashgpg --list-secret-keys --keyid-format LONGExample:
textrsa4096/3AA5C34371567BD2 2026-07-10 [SC]Record the long key ID (
3AA5C34371567BD2). You'll use this value when configuring Git.
Add Your Public GPG Key to GitLab
Export your public key.
bashgpg --armor --export <KEY_ID>Copy the entire output, including:
text-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----In GitLab, open User Settings > GPG Keys.
Paste the public key and select Add key.
Confirm the key status shows as Verified in GitLab.
Configure Git
Configure Git to sign commits using your GPG key.
Configure your Git identity.
bashgit config --global user.email "<GITLAB_EMAIL_ADDRESS>" git config --global user.name "<FIRSTNAME LASTNAME>"Ensure this email address matches a verified email address on your GitLab account. Otherwise, GitLab cannot verify your signed commits.
Configure Git for commit signing.
bashgit config --global user.signingkey <KEY_ID> git config --global commit.gpgsign trueVerify the configuration.
bashgit config --list | grep -E "user|gpg|commit"Confirm the output includes:
- Your GitLab email address.
- Your GPG signing key.
trueforcommit.gpgsign.
Configure Pinentry
Configure pinentry-mac so macOS can prompt for your GPG passphrase when signing commits.
Install
pinentry-mac.bashbrew install pinentry-macConfigure GPG to use
pinentry-mac.bashecho "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.confConfigure the GPG terminal environment variable for zsh.
bashecho "export GPG_TTY=\$(tty)" >> ~/.zshrc source ~/.zshrcRestart the GPG agent.
bashgpgconf --kill gpg-agent
Verify Commit Signing
Create a test commit.
bashgit commit --allow-empty -m "test commit signing"Enter your GPG passphrase when prompted.
Verify the commit signature.
bashgit log --show-signature -1The commit should appear as Verified in GitLab.
Optional: Configure VS Code Commit Signing
If you choose to sign commits from VS Code:
Open VS Code Settings (cmd+ or Preferences > Settings).
Search for Git: Enable Commit Signing and enable the setting.
VS Code will use your existing GPG configuration when creating signed commits.
Troubleshooting
GPG fails to sign the commit
If Git returns:
error: gpg failed to sign the data
fatal: failed to write commit objectRun:
echo "test" | gpg --clear-signIf signing succeeds, GPG is functioning correctly.
If you receive a timeout error, restart the GPG agent:
gpgconf --kill gpg-agentThen retry the commit.
Git cannot find the signing key
If Git returns:
could not find identity matching specified user-id
error: gpg failed to sign the data
fatal: failed to write commit objectVerify that gpg.format is not configured.
git config --get gpg.formatIf a value is returned, remove it.
git config --unset gpg.formatIf the setting persists, remove the gpg.format entry manually from your ~/.gitconfig file, then retry the commit.
Enable Git trace logging
For additional troubleshooting, enable Git trace output.
GIT_TRACE=1 git commit -S -m "test commit"