A couple of months ago I noticed that commits I’ve done through the GitHub web interface were receiving a “Verified” badge while commits done through the Git command line in WSL (Windows Subsystem for Linux) at my local dev machine weren’t.
I’m all for badges so I followed the steps found at About commit signature verification to setup GPG signing. The thing is, there was something still missing and as a result, when trying to commit I was getting an error message as follows:
error: gpg failed to sign the data
fatal: failed to write commit object
Fortunately, the solution is simple. Export a variable named GPG_TTY as follows:
export GPG_TTY=$(tty)
I ended appending it to ~/.bashrc so as to persist it between terminal sessions.
For the benefit of your readers please consider revising this post to explain why this worked for you.
I’m not sure why this setting has to be done manually, but it is stated in the documentation for gpg-agent (http://manpages.ubuntu.com/manpages/bionic/man1/gpg-agent.1.html) and it has been this way for a long, long time (https://github.com/gpg/gnupg/blame/abaa732d6b0cade814bdbda36a2d0cb5d79b1684/doc/gpg-agent.texi#L84).
There’s an opened issue over at GnuPG (https://dev.gnupg.org/T3412) describing the issue on Debian, but I was able to reproduce the error on Ubuntu 18 and 19, and CentOS 8.0 as well.