Error: gpg failed to sign the data

If you’re facing issues signing with gpg, here’s what you can do:

$ git commit -m "initial commit"
error: gpg failed to sign the data
fatal: failed to write commit object

Double-check that gpg is working:

$ echo "test" | gpg --clearsign
Hash: SHA256

gpg: signing failed: No pinentry
gpg: [stdin]: clear-sign failed: No pinentry

Note: It’s not working; Looks like it cannot find pinentry.

Quick Fix

Find out the location of pinentry:

# Find out pinentry location
$ which pinentry

Stop the running gpg daemon:

# kill running daemon
pkill gpg-agent

Start daemon:

# run new daemon
gpg-agent --pinentry-program=/run/current-system/profile/bin/pinentry --daemon