27

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 <[email protected]>"
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?

4 Answers 4

36

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

1
  • 2
    This answer perfectly solved for me, where I have matching gpg-agent and gpg but the agent is refusing to load.
    – sfuqua
    Aug 23, 2021 at 20:23
15

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
1
  • 3
    Current versions of gpg4win do not call the gpg executable gpg2 anymore, so git now requires the full path to the executable (with forward slashes).
    – LB--
    Feb 16, 2018 at 23:12
4

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

1

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.

You must log in to answer this question.

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