GPG failed to sign the data for a git commit. But it works after signing a local file first?

Viewed 40

This is a very weird behavior. I am using gpg (GnuPG) 2.2.19, and I am trying to sign a git commit. The first time I try I get an error saying:

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

... but then someone suggested in another Stack Overflow question that if you sign a local dummy file first, and then try again to sign the commit that would work. And it does! But why? How can I avoid doing weird thing of signing a local file first every time I want to sign a git commit?

I am using WSL on Windows 11, so all these take place in WSL.

1 Answers

Ok I don't know if this will solve it for everyone, the comments in the original question provide some other solutions that did not work for me. But I did find a solution in this guide in this section Configure pinentry to use the correct TTY

It was an issue where I had to specify the correct TTY as described in this gpg-agent documentation

So to achieve this I had added the following in my ~/.bashrc (or ~/.zshrc in my case when using ohmyzsh):

# update tty for gpg-agent
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
unset SSH_AGENT_PID
export GPG_TTY=$(tty)
gpgconf --launch gpg-agent
Related