Home > Software design >  Issues with signing git commits with GPG
Issues with signing git commits with GPG

Time:05-06

I'm having some trouble setting up GPG commit signing with github after performing a windows reinstall.

Issue:

When commiting, GPG signing fails returning this error:

gpg: skipped "993E2EFC8503C42F": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

Everything I have googled about this issue all point to setting gpg.program to the location of the GnuPG gpg executable ("C:\Program Files (x86)\GnuPG\bin\gpg.exe") Which sadly, has not solved my issue.

Performing gpg --list-secret-keys --keyid-format=long in git bash returns my gpg keys, however performing the same command in powershell or cmd, does not, which i believe might be my issue, although i dont know how to go about fixing this.

Steps already taken:

  1. installed GPG4Win from here
  2. installed git from here
  3. followed the GPG setup guide by github
  4. set git config --global user.name "name..." and git config --global user.email "email"
  5. set git config --global user.signingkey to my gpg key
  6. set git config --global gpg.program to "C:\Program Files (x86)\GnuPG\bin\gpg.exe" as described by various other online tutorials and answers
  7. set git config --global commit.gpgsign to true

Expected result:

Successfully submit a verified commit

bonus info

  • Git version: 2.36.0.windows.1
  • OS: windows 11 22000.613

CodePudding user response:

I've managed to figure it out!

I'm ultimately not quite sure what the issue was specifically, however, after uninstalling GPG4Win and Git, then only reinstalling Git and going through the GPG setup process, I'm now able to perform verified commits. this is using Gits bundled GPG program and no other GPG related installation.

not sure if this will help anyone else, but if you're on windows having this issue, try running through the gpg setup process WITHOUT GPG4Win installed and just use gits bundled GPG executable.

remember to set commit.gpgsign to true and tell git your signing key like so git config --global user.signingkey "your key id" if you only want to set the signing key for specific project you can cd to the project directory and run the same command WITHOUT the --global tag.

  • Related