Skip to content

Instantly share code, notes, and snippets.

Last active June 6, 2023 15:38
What would you like to do?
How to understand the `gpg failed to sign the data` problem in git


You have installed GPG, then tried to commit and suddenly you see this error message after it:

error: gpg failed to sign the data
fatal: failed to write commit object


For understanding what's going on, first check what git is doing, so add GIT_TRACE=1 at the beginning of the command you used before (git commit or git rebase):

GIT_TRACE=1 git commit

With that you can see what GPG is doing: Probably you will see something like this

10:37:22.346480 run-command.c:637       trace: run_command: gpg --status-fd=2 -bsau <your GPG key>

(Check if your GPG key is correct)

Execute that gpg command again in the command line:

gpg --status-fd=2 -bsau <your GPG key>

👆🏻 With this now you could see what happened in detail!


We can have many problems, but I list what I found:

  1. It could be that the GPG key was expired:
  2. Another thing could be that the secret key was not set properly (In my case the message said gpg: signing failed: No secret key as it can be see in the image below). image It means that is not finding the key that was set. You would need to set up the GPG key in Git (again):
    • List the secret keys available in GPG.
    gpg --list-secret-keys --keyid-format=long
    • Copy your key
    • Set your key for your user in git
    git config --global user.signingkey <your key>
  3. You can see in the thread of this gist other ways to find the solution to other problems. I recommend to read the Github guide for signing commits with GPG.

Hope it helps!

Copy link

After struggling for hours, I finally get rid of this error.
Thanks man

Copy link

@NirajanMahara lifesaver!
Your solution worked out for me.

Copy link

thyarles commented Mar 8, 2023

I you're on WSL2, maybe this can help:

  • Add those lines to ~/.gnupg/gpg.conf

    pinentry-mode loopback
  • Add this line to ~/.gnupg/gpg-agent.conf


Copy link

gauravk-io commented Apr 4, 2023

I was getting the error

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

I just need to set the

gpg.program="C:\Program Files (x86)\GnuPG\bin\gpg.exe"



THANKYOU @victorjatoba

Copy link

This exactly solved my problem. Great thanks! @victorjatoba

Copy link

renjujv commented Apr 24, 2023

Copy link

pro-akim commented May 2, 2023

Thanks @paolocarrasco, you are awesome

Copy link

I just killed the gpg-agent and started again and it worked for me

killall gpg-agent
gpg-agent daemon

Yes, sometimes pinentry-mac update brakes gpg-agent

Copy link

T410 commented May 12, 2023

Additionally, if you are using a mac and you are experiencing an issue, try step number 8:

$ brew install pinentry-mac
$ echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
$ killall gpg-agent

basically, it allows/forces your device to ask the password of the key

Copy link

Super useful, thank you very much!

Copy link

Thanks :) @T410

Copy link

klubi commented Jun 6, 2023

I'm running into similar issue, but It may be a layer deeper.
When I run gpg --status-fd=2 -bsau ... I get

[GNUPG:] PINENTRY_LAUNCHED 106 curses 1.1.0 - - -
gpg: signing failed: Inappropriate ioctl for device
[GNUPG:] FAILURE sign 83918950
gpg: signing failed: Inappropriate ioctl for device

I'm running that in jenkins, and I assume Jenkins is awaiting for passphrase input, but I can't seem to figure out how to sent it to it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment