13

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
  • 307
  • 2
  • 7

4 Answers4

11

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
  • 3,616
  • 2
  • 19
  • 27
8

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,129,465
  • 480
  • 4,036
  • 4,755
  • 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
6

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"

4

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
  • 10,343
  • 7
  • 50
  • 55