4

Currently, I am on Windows running git 2.15.0.windows.1, gpg 2.2.1, and gpg-agent 2.2.1. I am trying to sign a commit with git via pinentry/gpg-agent, however, when signing a commit via git, pinentry never appears and git throws an error. I am still able to sign commits via gpg, but not through git.

> git commit -a -S -m "Signed Commit"
gpg: gpg-agent is not available in this session
gpg: Sorry, no terminal at all requested - can't get input
error: gpg failed to sign the data
fatal: failed to write commit object

I can still sign via gpg without git:

My gpg.conf:

keyserver hkp://keys.gnupg.net
no-tty
use-agent

When I remove the last two lines, gpg will still pop up pinentry, and git can then sign commits again however it will only accept passphrase entry via command line instead of pinentry.

How can I fix the original error and have signing commits pop up pinentry?

2 Answers 2

0

I was able to fix it by setting the correct git config options.

First, get the correct signature by running gpg --list-signatures and look for the signature ID that's marked either sig or sig 3

sig 3        54ABFD17372D7B88  ...

Then set the git config user.signingkey to it:

git config --global user.signingkey 54ABFD17372D7B88

And finally, set gpg.program to the location of your gpg.exe binary.

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

Now when you commit with -S or --gpg-sign, you should see the pinentry box.


If you want this to work with most GUI programs, such as VS Code, GitHub Desktop, and IDEA-based products (PyCharm, Android Studio, PHPStorm, etc), you should set commit.gpgsign to true:

git config --global commit.gpgsign true

this will sign every commit. If you don't want to sign a specific commit, use --no-gpg-sign when commiting.

0

I ended up having more than one gpg client installed. I guess I accidentally installed it when I updated my git client recently, since I had installed it seperately on some other occasion. I had to assign the gpg.program to get it working correctly again.

git config --global gpg.program "C:\Path\To\My\Custom\gpg.exe"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .