33

When I do git commit -a -S -m "Commit Message", I get this error:

You need a passphrase to unlock the secret key for
user: "Username (Gpg Key) <email-id>"
2048-bit RSA key, ID 2487BE7C, created 2016-10-03

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

But, it doesn't even ask/prompts for my passphrase when I commit. So, how and where do I enter my passphrase while using gpg's -S flag?

Dawny33
  • 10,543
  • 21
  • 82
  • 134
  • 1
    Are you sure gpg can read input? If stdin is closed, you would see the above error message. If the git command is not run in an interactive shell, then you might need to have gpg-agent running in order to handle the passphrase input. – G. Sliepen Oct 03 '16 at 10:47
  • @G.Sliepen Possible to tell how to start it please? – Dawny33 Oct 03 '16 at 10:58

3 Answers3

40

I had the similar thing. I had the gpg and gpg2 binaries, both pointing to GPG version 2.0.30. I wasn't being prompted for my passphrase.

In your bash profile (I did it in my .zshrc file) add the following line:

export GPG_TTY=$(tty)
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
DiegoRBaquero
  • 1,208
  • 10
  • 14
11

It stopped prompting me, so I had to kill the daemon

ps aux | grep gpg
mark              3129   0.0  0.0  4397952    820   ??  Ss    8Mar19   0:28.84 gpg-agent --homedir /Users/Mark/.gnupg --use-standard-socket --daemon
mark             18137   0.0  0.0  4286492    848 s000  R+    3:43pm   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn gpg

then

sudo kill -9 3129

Then it worked. It may be a slightly different issue.

Rambatino
  • 4,716
  • 1
  • 33
  • 56
1

If you are using OSX. It seems like a gpg update (of brew) changed to location of gpg to gpg1, you can change the binary where git looks up the gpg:

git config --global gpg.program gpg1

See this medium blog post.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535