Search code examples
gitgithubgnupg

Git GPG signing fails without a clear message


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?


Solution

  • 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.