0

I know there are a lot of similar questions, but basically, git commit gives me

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

However, thanks to this answer, I can sign commit by signing a random file via gpg in the command line first. This works, but it is pretty annoying. Why do I have to do that ?

I'm using Manjaro KDE.

  • When you do the command-line file signing, do you have to feed a password / pass-phrase to a GPG agent, which then lingers for a while to be able to sign the commit without first getting a password / pass-phrase? If so, consider tickling the agent to do the same pre-load without having to sign a file. That's still annoying, so [see the documentation](https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html). – torek Aug 25 '21 at 20:42
  • 1
    @torek yes, the password is saved because I can enter it in the terminal, but when I let VSCode or Intellij Idea commit and do stuff, if the password isn't "temporary saved" it does that error. I didn't understand what you wanted me to do with the documentation. – Bananasmoothii Aug 27 '21 at 17:05
  • It *may* be the case that you can set GPG_TTY to point to a terminal where you can enter the password. I'd poke around with the documentation to see if there is some workaround. – torek Aug 28 '21 at 11:55

2 Answers2

1

You might want to specify the GPG program for Git with

git config --global gpg.program gpg2

and enable signing for all commits (otherwise, add -s to each Git command)

git config --global commit.gpgsign true

Use gpg --list-keys to find your key and specify the use of this key in Git:

git config --global user.signingkey <Your GPG Key>

GPG will ask for the password when you execute git commit.

Reference: https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work

Alvin Tang
  • 33
  • 6
  • 1
    Have you also added `GPG_TTY=$(tty)` and `export GPG_TTY` to `.bashrc`? You might like to refer to [this answer](https://stackoverflow.com/a/42265848/12716154). – Alvin Tang Sep 13 '21 at 13:09
1

Thanks to Alvin Tang for giving me the solution that was so simple!

I just had to add these two line:

GPG_TTY=$(tty)
export GPG_TTY

at the bottom of the file located at ~/.bashrc.