Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gpg "failed to write commit object"

I'm trying to enable commit signing on OS X Mojave.

git commit -S -am "Test"

The error is:

error: gpg failed to sign the data
fatal: failed to write commit object

What I tried:

  • gpg works fine (see below), did not install gpg1 or gpg2
  • Installed GPG KeyChain and added a new key (even added a separate sign-only subkey whithin)
  • Installed pinentry
  • gpg2 --clearsign works fine (generates a new .asc file for files, outputs text for plain text)

Questions I looked into and tried every option:

  • gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]
  • Git error - gpg failed to sign data

What am I doing wrong?

like image 577
Alex Buznik Avatar asked Mar 07 '19 06:03

Alex Buznik


2 Answers

Try with echo "foobar" | gpg --clearsign. It should ask for your key's passphrase and return the signature. If instead you see the following error message:

error: gpg failed to sign the data
fatal: failed to write commit object

You might want to try running export GPG_TTY=$(tty). If after testing again you're prompted for the password and it works, run this everytime on startup, adding it to ~/.bashrc, which is actually required according to gpg-agent's documentation, as mentioned in this dev.gnupg thread and which you can verify with man gpg-agent.

I also found this gitHub gist very useful.

like image 145
LucasFA Avatar answered Sep 28 '22 16:09

LucasFA


I also had this problem. I found a good solution. Just try to sign a file before you commit.

$ touch a.txt
$ gpg --sign a.txt

Then, the OS will let you input the password. If this step is OK, now you can commit by signing correctly.

like image 30
mkckr0 Avatar answered Sep 28 '22 18:09

mkckr0