You have installed GPG, then tried to commit and suddenly you see this error message after it:
error: gpg failed to sign the data
fatal: failed to write commit object
For understanding what's going on, first check what git is doing, so add GIT_TRACE=1
at the beginning of the command you used before (git commit
or git rebase
):
GIT_TRACE=1 git commit
With that you can see what GPG is doing: Probably you will see something like this
10:37:22.346480 run-command.c:637 trace: run_command: gpg --status-fd=2 -bsau <your GPG key>
(Check if your GPG key is correct)
Execute that gpg command again in the command line:
gpg --status-fd=2 -bsau <your GPG key>
👆🏻 With this now you could see what happened in detail!
We can have many problems, but I list what I found:
-
It could be that the GPG key was expired: https://stackoverflow.com/a/47561300/532912
-
Another thing could be that the secret key was not set properly (In my case the message said
gpg: signing failed: No secret key
as it can be see in the image below). It means that is not finding the key that was set. You would need to set up the GPG key in Git (again):- List the secret keys available in GPG.
gpg --list-secret-keys --keyid-format=long
- Copy your key
- Set your key for your user in git
git config --global user.signingkey <your key>
-
Another popular solution that could help was shared here by @NirajanMahara: https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374?permalink_comment_id=3767413#gistcomment-3767413
-
You can see in the thread of this gist other ways to find the solution to other problems. I recommend to read the Github guide for signing commits with GPG.
Hope it helps!
if all of the above did not work for you
I got into a slightly different problem, everything up there ALREADY CHECKED, somehow my
gpg
signing stopped working - and i don't want to restart my server. After digging around i found this logSome output of
systemctl --user status gpg-agent
Note that until this point, it's not about
git
anymore, it's aboutgpg
and distro-specific issues.FIXED (the root cause is
pinentry
screwed things up)Create
gpg-agent.conf
if you don't have one under your home dir and add the line below (pinentry-program /usr/bin/pinentry-curses
)Then you have to restart
gpg-agent
by issuingsystemctl --user restart gpg-agent
and you may want to log-in/out. Make sure toexport GPG_TTY=$(tty)
and test again. Good luckCheck my write-up here for the summary nguyenvulong/QA#25