Guide written for Windows 11 Pro.
If you have not set up GPG keys yet, refer to Setting up GPG Keys with PowerShell (coming soon).
Configure Git Global Variables
- List your GPG keys:
The key ID is the part after
/on the line starting withsec.gpg --list-secret-keys --keyid-format LONG - Configure Git to use your GPG key:
git config --global user.signingkey YOUR_KEY_ID - Optional — sign all commits by default:
git config --global commit.gpgsign true - Print your public GPG key:
gpg --armor --export YOUR_EMAIL_ADDRESS
Add Your GPG Key to GitLab
- Sign in to GitLab.
- Go to your user settings, then to the GPG Keys section.
- Paste your public GPG key into the text area and click Add key.
Verify
Commit and push changes to your repository:
git commit -S -m "Your commit message" Common Errors
1. No Secret Key
gpg: skipped "A6D52EAF2B1C52E5": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object
Git for Windows ships with a minimal version of GnuPG that uses
~/.gnupg/ (C:\Users\YourUsername\.gnupg\) for configuration
and key storage. Gpg4win, on the other hand, uses %APPDATA%\gnupg. If you
have both installed, Git may be looking in the wrong place.
- Check your Git global configuration:
git config --global --listLook for a
gpg.programentry. If it is missing, Git will use its bundled minimal GnuPG install.user.name=Your Name user.email=ell@myemail.com user.signingkey=12334asd3 commit.gpgsign=true - Set the GPG program in your Git configuration:
git config --global gpg.program "C:/Program Files (x86)/GnuPG/bin/gpg.exe"ⓘYour path may differ. Confirm the correct path before running this command.
- Confirm the change:
git config --global --listuser.name=Your Name user.email=you@youremail.com user.signingkey=12334asd3 commit.gpgsign=true gpg.program=C:/Program Files (x86)/GnuPG/bin/gpg.exe
2. Bad Data Signature
gpg: bad data signature from key PROBLEMID: Wrong key usage (0x19, 0x2) -
List the key ID Git is configured to use:
git config --global user.signingkey -
Check for the matching key:
gpg --list-secret-keys --keyid-format LONG
Ensure the key ID returned in step 1 matches a key in your keyring.
3. No Agent Running
gpg: can't connect to the gpg-agent: IPC connect call failed
gpg: keydb_search failed: No agent running
gpg: skipped "<signing-key>": No agent running
gpg: signing failed: No agent running
error: gpg failed to sign the data
fatal: failed to write commit object - Start the agent:
gpgconf --launch gpg-agent - Set the agent to auto-start on login via Task Scheduler:
- Search for Task Scheduler in the Windows Start menu.
- Click Create Basic Task and name it Gpg Agent Startup.
- Set the Trigger to When I log on.
- Set the Action to Start a program and enter:
gpgconf --launch gpg-agent - Confirm the prompt and click Finish.