Git error – gpg failed to sign data

I just started using git and I install git and gpg via homebrew.
For some reason, I get this error when i do git commit
I looked at so many other stackoverflow questions regarding this topic and none of them worked for me.
How can I fix this error so that I can upload successfully.

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

33 Answers
33

For troubleshooting, two things to first try:

  • run gpg --version, and make sure you have GnuPG version 2+ (not version 1) installed
  • run echo "test" | gpg --clearsign, to make sure gpg itself is working

If that all looks all right, one next thing to try:

  • run brew install pinentry to ensure you have a good tool installed for passphrase entry

If after that install, you re-try git commit and still get a “failed to sign the data” error, do:

  • run gpgconf --kill gpg-agent to kill any running agent that might be hung

Otherwise, some basic steps to run to check you’ve got a working GnuPG environment:

  • run gpg -K --keyid-format SHORT, to check that you have at least one key pair

If the output of that shows you have no secret key for GnuPG to use, you need to create one:

  • run gpg --gen-key, to have GnuPG walk you through the steps for creating a key pair

If you get an error message saying “Inappropriate ioctl for device”, do this:

  • run export GPG_TTY=$(tty) and/or add that to your ~/.bashrc or ˜/.bash_profile

Leave a Comment