Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT commit error - VSCODE in WSL2 (error: gpg failed to sign the data fatal: failed to write commit object)

I have VSCode installed

code --version

1.53.0 8490d3dde47c57ba65ec40dd192d014fd2113496 x64 Git version:

git --version

git version 2.27.0

I have active keys. When i commit i get the title error. I get the error in command line and clicking submit in vscode.

GIT_TRACE=1 git commit -m "start"

11:50:45.606604 git.c:442 trace: built-in: git commit -m start 11:50:45.649422 run-command.c:663 trace: run_command: /usr/bin/gpg --status-fd=2 -bsau "active-key"

error: gpg failed to sign the data

fatal: failed to write commit object

gpg --status-fd=2 -bsau "active key"

[GNUPG:] KEY_CONSIDERED "ACTIVE KEY" 2

[GNUPG:] BEGIN_SIGNING H10

^C

gpg: signal Interrupt caught ... exiting

It hangs until i stop. Any ideas?. Thank you.

like image 975
C.D. I. Avatar asked Oct 25 '25 21:10

C.D. I.


2 Answers

I managed to fix my WSL2 setup by following those instructions https://www.39digits.com/signed-git-commits-on-wsl2-using-visual-studio-code

The most important was to install GPG4Win in Windows 10... and add in ~/.gnupg/gpg-agent.conf

default-cache-ttl 34560000
max-cache-ttl 34560000
pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"

Visual Studio Code is installed on the Windows 10 side and as such we need that graphical pinentry to enter a passphrase when committing code from the editor.

like image 183
frankyt79 Avatar answered Oct 28 '25 14:10

frankyt79


I had similar problems under WSL2 (unbuntu 20.04) and was able to recreate your error.

The initial situation:

GPG key is available. But be careful there are many outdated instructions so use: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key

gpg --full-generate-key in my case

The solutions:

  1. You use git with configured commit.gpgsign = true because you get the error in the UI and the console. If this is not necessary, then deactivate the signature locally in the project folder: git config commit.gpgsign false or globally git config --global commit.gpgsign false

  2. You want to sign and use VSCode. The core of the problem is the GPG installation in WSL2, because that is what is used. The GPG agent is missing and Windows cannot unlock the keys. Install the agent in WSL2 and configure it. As soon as you activate the GPG key under a WSL2 terminal, you can use the cached state. VSCode will then work for the configured time. If you want to enter a password under Windows, then read the solution here: No GPG passphrase prompt in Visual Studio Code on Windows 10 for signed git commits using WSL2

like image 25
jens.klose Avatar answered Oct 28 '25 14:10

jens.klose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!