4

I have an error with signing my commits by git commit -S -m 'test' and getting these errors:

error: gpg failed to sign the data
fatal: failed to write commit object

I already tried this solution and still not working right.

Also tried this and still nothing.

I have Macbook Pro 2017 with the latest macOS.

Is there any other solution how I can fix it and properly commit my commits to Github or Gitlab?

6
  • Please add the results of showing your key with gpg; I suspect the key has expired.
    – U. Windl
    Commented Dec 2, 2021 at 9:26
  • @U.Windl The gpg key was today created and today set. It can be still expired? If yes how I can check it? Commented Dec 2, 2021 at 9:36
  • Would git display exact information about the GnuPG invocation via GIT_TRACE=1 git commit -S -m 'test' ? Commented Dec 2, 2021 at 11:26
  • @NickolayOlshevsky Terminal display this. 16:27:37.452431 git.c:455 trace: built-in: git commit -S -m test 16:27:37.466454 run-command.c:668 trace: run_command: gpgsm --status-fd=2 -bsau xxxxxxxxxxxxxxx error: gpg failed to sign the data fatal: failed to write commit object Commented Dec 2, 2021 at 15:28
  • Looks like you are trying to use S/MIME instead of OpenPGP signatures, is it by intention? This article should be helpful on further troubleshooting: docs.github.com/en/authentication/… Commented Dec 2, 2021 at 15:34

4 Answers 4

6

I had the same issue. I solved it by:

  1. First ensure that the key is not expired: gpg --list-keys
  2. If it is still valid restart the gpg-agent: gpgconf --kill gpg-agent
  3. It should work now.
2

Fixed here using this command of topic: https://github.com/microsoft/vscode/issues/130415

$ export GPG_TTY=$(tty)
$ echo "test" | gpg2 --clearsign
0

First, make sure to use Git 2.40 (Q1 2023), which clarifies the error message.


Git 2.36 (Q2 2022) also improves that use case: newer version of GPGSM changed its output in a backward incompatible way to break our code that parses its output.
Adjustments have been made to accommodate these changes.

See commit b0b70d5, commit fa47dd6 (04 Mar 2022) by Todd Zullinger (tmzullinger).
See commit a075e79 (04 Mar 2022) by Fabian Stelzer (FStelzer).
(Merged by Junio C Hamano -- gitster -- in commit 21b839e, 13 Mar 2022)

gpg-interface/gpgsm: fix for v2.3

Helped-By: Junio C Hamano
Helped-By: Todd Zullinger

Checking if signing was successful will now accept '[GNUPG]: SIG_CREATED' on the beginning of the first or any subsequent line.
Not just explictly the second one anymore.

Gpgsm v2.3 changed its output when listing keys from fingerprint to sha1/2 fpr.
This leads to the gpgsm tests silently not being executed because of a failed prerequisite.
Switch to gpg's --with-colons output format when evaluating test prerequisites to make parsing more robust.
This also allows us to combine the existing grep/cut/tr/echo pipe for writing the trustlist.txt into a single awk expression.

git merge --no-ff -m msg signed_tag_x509_nokey &&
GNUPGHOME=. git log --graph --show-signature -n1 plain-x509-nokey
0

I already had GPG on my Windows PC, and gpg --list-keys would successfully list my key in Git Bash (not in the standard Windows Command Line), however, GitHub Desktop wasn't working for me.

The solution was to add Git's GPG binary to my PATH variable. So I added C:\Program Files\Git\usr\bin to the PATH, and GitHub Desktop began working.

NOTE: If you have Git installed on your PC, you likely already have GPG installed at: C:\Program Files\Git\usr\bin\gpg.exe.

Not the answer you're looking for? Browse other questions tagged or ask your own question.