22

I'm getting this error when trying to sign a commit:

git commit -S -m "test"
gpg: skipped "EF617ACA9EC3XXXX": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

This is the output of gpg --list-secret-keys --keyid-format LONG

The key is present there

sec   rsa4096/EF617ACA9EC3XXXX 2020-05-17 [SC] [expires: 2022-05-17]
      AD68154000A712DCD161D826EF617ACA9EC3XXXX
uid                 [ultimate] name <email@gmail.com>

And this is git config with the same key

user.signingkey=EF617ACA9EC3XXXX
user.email=email@gmail.com

Any idea what's wrong?

giveall
  • 404
  • 1
  • 3
  • 8

8 Answers8

27

git config --global gpg.program "c:/Program Files (x86)/GnuPG/bin/gpg.exe"

I installed with Kleopatra and generated my key within that. I was unable to create a commit until I ran the command above.

Eric Milliot-Martinez
  • 4,076
  • 3
  • 23
  • 28
11

Check first the git config gpg.program to see if this is gpg or gpg2 (as in here).

And type where gpg nd where gpg2 to check which path is considered for the GPG program.

I suggested to set gpg.program to gpg2, and copy your gpg.exe (assuming its version is a 2.x) to gpg2.exe

That should force Git/GPG to act as gpg2.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • gpg is in git config. Path to gpg.exe is correct too, and I don't have gpg2 at all (isn't it on linux only?) – giveall May 17 '20 at 09:05
  • @giveall The gpg currently shipped with Git for Windows is actually a gpg 2 -2.2.17) – VonC May 17 '20 at 09:07
  • @giveall What version of Git for Windows are you using? – VonC May 17 '20 at 09:08
  • 1
    @giveall Try and set `gpg.program` to `gpg2`, and copy your `gpg.exe` (assuming its version is a 2.x) to `gpg2.exe`, for testing. See also https://stackoverflow.com/a/46884134/6309 – VonC May 17 '20 at 09:10
  • @giveall Do you have GPG4Win installed? (as in https://gist.github.com/BoGnY/f9b1be6393234537c3e247f33e74094a#gistcomment-2718488) – VonC May 17 '20 at 09:13
  • git 2.26.2 (the latest one, I guess?), but I still don't have gpg2 or an option to install it along with git. – giveall May 17 '20 at 09:22
  • 3
    Anyway, renaming gpg.exe to gpg2.exe and changing it in the config helped, which is super weird. – giveall May 17 '20 at 09:23
  • @giveall Strage indeed. I have edited the answer to include that recommendation. – VonC May 17 '20 at 09:26
  • @giveall I still suspect you had another gpg.exe installed somewhere else (as in https://github.com/git-for-windows/git/issues/1249#issuecomment-570357527). Now that `gpg.program` is set to `gpg2`, you are forced to use the Git one. – VonC May 17 '20 at 09:30
  • I don't think so. where gpg2 points to that gpg2.exe I just made. – giveall May 17 '20 at 09:42
  • @giveall Through the Git config `gpg.program` – VonC May 17 '20 at 09:45
9

In case anyone is a dufus like me I was getting this error because I had the gitkey wrong while directly editing the file via: git config --global -e or code ~/.gitconfig or whatever flavor of editor you enjoy.

  • singingkey instead of
  • signingkey ‍♂️
CTS_AE
  • 12,987
  • 8
  • 62
  • 63
7

Was facing the same issue in windows 10 git bash. Doing this solved my problem. You could find this path by running where gpg

$ git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"

Naman Lakhwani
  • 117
  • 1
  • 2
1

Had this same problem on Windows 11 when trying to get GitHub Desktop to work. The answer given here solved the issue for me:

git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"
ntg_13
  • 11
  • 2
1

I have resolved my issue by setting the path of the gpg.exe from git itself.

git config --global gpg.program "C:\Users\myname\AppData\Local\Programs\Git\usr\bin\gpg.exe"
ER.SHASHI TIWARI
  • 917
  • 1
  • 10
  • 25
0

Another potential issue/resolution:

Make sure the email you set in Github is verified and that it exactly matches the email you used when you generated your GPG key.

I Stand With Israel
  • 1,971
  • 16
  • 30
-1

I hit this issue when trying to set up git commits signing on Windows.

In my case I had multiple gpg.exe installations, including the one at C:\Program Files\Git\usr\bin\gpg.exe. However, the default gpg command was executing a different gpg.exe, and generated the secret keys with it. Changing git's gpg.program option didn't work for me.

Ultimately, I just used git's gpg install to generate the secret key and that works like a charm:

cd "C:\Program Files\Git\usr\bin"
.\gpg --version
.\gpg --list-secret-keys --keyid-format=long
.\gpg --full-generate-key

etc
...
Arge
  • 85
  • 2
  • 9