33

I have the gpg-agent.exe running, but when I try to git commit, it complains that the GPG agent can not be found:

$ gpg-agent --daemon
gpg-agent[17440]: a gpg-agent is already running - not starting a new one

$ git commit -m "foo"

You need a passphrase to unlock the secret key for
user: "Oliver Salzburg <oliver.salzburg@gmail.com>"
4096-bit RSA key, ID 5826006B, created 2016-12-05

gpg: gpg-agent is not available in this session
Enter passphrase:

What is going on?

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311

4 Answers4

49

When this message is issued upon commiting:

gpg: can't connect to the gpg-agent: IPC connect call failed
gpg: keydb_search failed: No agent running

The following command starts the gpg-agent on Windows:

gpg-connect-agent reloadagent /bye

After reloading the agent the signing password prompt is displayed properly.

Environment
Windows 11 Home 21H2
git version 2.32.0.windows.2
gpg (GnuPG) 2.3.1
gpg-agent (GnuPG) 2.3.1

rbento
  • 591
16

It is likely that your gpg-agent and gpg binaries are from different packages.

This can happen when you're using Git Bash (which ships with gpg) and you're installing GnuPG4Win additionally. The latter ships with a more recent version.

You can verfiy if this is your problem, by checking the version of both programs:

% gpg-agent --version
gpg-agent (GnuPG) 2.1.7

% gpg --version                                                               
gpg (GnuPG) 1.4.19

If this is your problem, you should tell git which gpg binary to use:

% git config --global gpg.program gpg2
Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
7

This should work on Windows 11, mind that I have installed GnuPG, which causes the bug (probably) in the first place.

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

For me this also fixed the Bug, that git-towers had a problem connecting to the service.

PS: Worked for me in Windows PowerShell

justTil
  • 71
4

In addition to what others said you should also check your .gitconfig file. In my case I just needed to add quotes to the executable path: screenshot of gpg section on .gitconfig file

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

I got this error when trying to sign commits for the first time after reeboting and was able to reproduce it by killing gpg, gpg-agent, and git processes. Apparently it didn't catch that setting at first and relied on what was installed on C:\Program Files\Git\usr\bin.