Configure Commit Signing on Windows with GPG
Overview
This article explains how to configure your Windows machine 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 Windows 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 Gpg4win.
powershellwinget install GnuPG.Gpg4winAlternatively, download the installer from Gpg4win.
Verify the installation.
powershellgpg --version git --version
Generate a GPG Key
Generate a new GPG key.
powershellgpg --full-gen-keyWhen prompted:
- Select RSA and RSA.
- 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.
powershellgpg --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.
powershellgpg --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.
Configure Git
Configure Git to sign commits using your GPG key.
Configure your Git identity.
powershellgit 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.
powershellgit config --global user.signingkey <KEY_ID> git config --global commit.gpgsign true git config --global gpg.program gpgVerify the configuration.
powershellgit config --list | Select-String -Pattern "user|gpg|commit"Confirm the output includes:
- Your GitLab email address.
- Your GPG signing key.
gpgforgpg.program.trueforcommit.gpgsign.
Verify Git Commit Signing
Create a test commit.
powershellgit commit --allow-empty -m "test commit signing"Enter your GPG passphrase when prompted.
Verify the commit signature.
powershellgit log --show-signature -1The commit should appear as Verified in GitLab.
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.
$env:GIT_TRACE=1
git commit -S -m "test commit"