Git GPG signing fails without a clear message

Viewed 3153

If I set my Git to sign with my GPG key it fails. I've tried GIT_TRACE and it doesn't really give me any more info:

$ GIT_TRACE=1 git commit
15:29:35.112157 git.c:344               trace: built-in: git 'commit'
15:29:35.115745 run-command.c:626       trace: run_command: 'code --wait' '/Users/b/VurbAgency/haarlem.github.io/.git/COMMIT_EDITMSG'
15:29:52.884006 run-command.c:626       trace: run_command: 'gpg' '--status-fd=2' '-bsau' 'SECRETKEYID'
error: gpg failed to sign the data
fatal: failed to write commit object

When I try to run 'gpg' '--status-fd=2' '-bsau' 'SECRETKEYID' it just hangs after saying BEGIN_SIGNING H8 and doesn't do anything anymore.

Any ideas on how to solve this or avenues as to research?

4 Answers

I stumbled upon this when encountering the same error and I was already on the latest version of gpg (2.2.17). For me, it turned out to be multiple things.

  1. Before committing I had to run $ export GPG_TTY=$(tty). This then prompted the passphrase prompt to appear.
  2. If I used a passphrase with a special character it didn't work (the prompt said I had a bad passphrase when trying to use), so I had to only use alphanumeric characters.

And if you're doing this to get verified commits on GitHub ensure the name and email address match what you have on GitHub.

I've updated GPG on my mac using brew upgrade gpg after I saw my GPG was at version 2.2.5 and the newest was 2.2.10.

This has fixed the issue, for now. However, I still have no idea about what the cause of this problem was.

If you have installed gpg using Homebrew, and are also using GPGTools, you need to uninstall Homebrew's gpg.

# Uninstall gpg in homebrew so that it uses the gpg in GPGTools instead
$ brew uninstall gpg

# You might need to do some extra cleanup afterward as well:
$ rm -r /opt/homebrew/etc/gnupg

# Restart the gpg-agent so that it uses the correct one:
$ gpgconf --kill gpg-agent

After that, git was able to sign my commits again.

I ran into the same issue. In the GnuPG configuration file ~/.gnupg/gpg-agent.conf, the pinentry-program path was pointing to pinentry-mac, which was missing.

Running brew install pinentry-mac fixed it.

Related