Search code examples
gitvisual-studio-codegnupggpg-agent

git commit with gpg key does not work from VSCode


Added a gpg key to sign commits.

After all the configuration is done, I am able to sign via git cli.

But when I commit using vscode it opens a terminal window so I can enter my key password. The window appears a little buggy and does not accept the password and returns the error in vscode:

error: gpg failed to sign the data

When I restart gpg-agent and manage to commit via cli.

When I type the password through the cli, it is stored in that section of the terminal and I manage to commit through vscode. When you close the section, the error returns.

I'm using wsl2 with linux Ubuntu 20


Solution

  • I found a solution...

    Steps required:

    Install GPG4Win from https://www.gpg4win.org. Nothing other than the default gnupg is required, but I installed Kleopatra too in case it came in handy elsewhere.

    Edit ~/.gnupg/gpg-agent.conf and change the pinentry

    pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"