You have linked GPG to git and Github, following the instructions on the documentation, but when you tried to sign a commit this message shows up:
error: gpg failed to sign the data
fatal: failed to write commit object
You can track what GPG and git are trying to do with GIT_TRACE=1
:
$ GIT_TRACE=1 git commit -S -m "Trying to commit something..."
#-S is not needed if you have set `git config commit.gpgsign` to `true`
If the result looks similar to this:
11:32:49.709208 git.c:328 trace: built-in: git 'commit' '-S' '-m' 'Trying to commit something...'
11:32:49.712102 run-command.c:626 trace: run_command: 'gpg' '--status-fd=2' '-bsau' '<your-gpg-key>'
error: gpg failed to sign the data
fatal: failed to write commit object
You can try to manually rerun the command that caused the error:
$ gpg --status-fd=2 -bsau <your-gpg-key>
This should give you a more precise error.
If you are tying to use GPG-signed commits from a WSL shell and you have correctly followed all the steps in the documentation one possible solution for your problem is to add to your file .bashrc
(or .zshrc
if you are using zsh like me) this line:
export GPG_TTY=$(tty)
It will enable a passphrase prompt for GPG. After that you will be prompted to insert your key passphrase from GPG, and then the problem should be resolved. This is the same problem that occured to me, basically the keys and the configuration is working well but GPG didn't asked you the passphrase.
Note: Even if you are not using WSL you can to try this solution, especially if you are getting an Inappropriate ioctl for device error or GPG doesn't ask you the passphrase.
I also found online this solutions for Mac OS X users:
brew upgrade gnupg
brew link --overwrite gnupg
brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent
This should install gpg2
and configure it.
Other possible causes of the error may be:
- The key is expired, like in this case.
- The secret key wasn't set.
- Something had been appended to the key, or other typing error.
- The key was generated in the wrong format.
- Some linux distos use
gpg2
orgpg1
instead ofgpg
.
If none of these solutions worked you can give a look at this official GPG troubleshooting page.
Hope that helps.
Follow the below url to setup signed commit https://help.github.com/en/articles/telling-git-about-your-signing-key
if still getting gpg failed to sign the data fatal: failed to write commit object
this is not issue with git ,this is with GPG follow below steps
gpg --version
echo "test" | gpg --clearsign
if it is showing:
then use
export GPG_TTY=$(tty)
then try again
echo "test" | gpg --clearsign
in which PGP signature is.Output:
git config -l | grep gpg
Output:
git config --global commit.gpgsign true
https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0/55993078#55993078