Skip to content

Instantly share code, notes, and snippets.

@Peredery
Last active March 12, 2024 10:12
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Peredery/38d0538dd34381bbd9d13414269a1f27 to your computer and use it in GitHub Desktop.
Save Peredery/38d0538dd34381bbd9d13414269a1f27 to your computer and use it in GitHub Desktop.
FIX - gpg failed to sign the data fatal: failed to write commit object

FIX - gpg failed to sign the data fatal: failed to write commit object

!!! For M1/M2 apple silicon see this comment:

https://gist.github.com/Peredery/38d0538dd34381bbd9d13414269a1f27?permalink_comment_id=4559612#gistcomment-4559612

For MacOS | Mojave | High Sierra

Step 1 - Upgrade current gpg

brew upgrade gnupg

Step 2 - Install pinentry-mac

brew install pinentry-mac 

Step 3 - Update gpg-agent.conf

echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf 

Step 4 - Restart gpg-agent

killall gpg-agent && gpg-agent --daemon

Step 5 - Configure git to use GPG

git config --global gpg.program gpg
git config --global commit.gpgsign true
@shaunsim15
Copy link

shaunsim15 commented May 6, 2023

This seemed to work for me on my MacBook Pro (macOS Ventura) with Apple M1 Pro chip! But I had to do the following extra things:

  1. Run brew reinstall gnupgbefore the upgrade command in Step 1
  2. Instead of typing in echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf for Step 3, I had to type in echo "pinentry-program opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf (I found the path by running which pinentry-mac in the terminal)
  3. Instead of typing in git config --global gpg.program gpg in Step 5, I had to type in git config --global gpg.program /opt/homebrew/bin/gpg (I found the path by running which gpg in the terminal)

For further context, after I added git tracing to my commit: GIT_TRACE=1 git commit -a -m 'signing test',

the error message I got was:

16:56:06.xxxxxx git.c:xxx               trace: built-in: git commit -a -m 'signing test'
16:56:06.xxxxxx run-command.c:xxx       trace: run_command: /opt/homebrew/bin/gpg --status-fd=2 -bsau <NameOfMyKeyID>
error: gpg failed to sign the data
fatal: failed to write commit object

@fwqaaq
Copy link

fwqaaq commented May 10, 2023

Thanks, I use @shaunsim15 ways, it doesn't need to add GIT_TRACE=1 git commit -a -m 'signing test' for me, but to execute killall gpg-agent && gpg-agent --daemon at last.

@shaunsim15
Copy link

@fwqaaq yeah the GIT TRACE was just to show others exactly where my git commit was failing- gpg failed to sign the data fatal: failed to write commit object isn't very specific about what's gone wrong!

@fwqaaq
Copy link

fwqaaq commented May 10, 2023

@shaunsim15 Thank you very much!

@vsaladhagu
Copy link

thank you so much, worked for me !!

@menzen
Copy link

menzen commented Jun 8, 2023

super nice, works for me too !! THX

@mamiu
Copy link

mamiu commented Jul 24, 2023

GPG Git integration on macOS Ventura (and newer versions):

Here are all steps combined to setup and integrate GPG and Git on the latest macOS:

brew reinstall gnupg
brew upgrade gnupg
brew link --overwrite gnupg
brew install pinentry-mac
echo "pinentry-program $(brew --prefix)/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
git config --global gpg.program (brew --prefix)/bin/gpg
git config --global commit.gpgsign true
sudo chown -R $USER ~/.gnupg/
chmod 700 ~/.gnupg/
killall gpg-agent && gpg-agent --daemon

Thanks to @Peredery and @shaunsim15!

@kushal-chhetri7
Copy link

Thanks worked For me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment