Skip to content

Instantly share code, notes, and snippets.

@Peredery
Last active May 19, 2024 08:36
Show Gist options
  • 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
@mamiu
Copy link

mamiu commented Jul 9, 2022

Although this Gist is already more than 3 years old it still seems to be the only solution (or to be more precise: workaround).

microsoft/vscode#43809 (comment)

@abdelhegazi
Copy link

I double that, this is a great Gist

@NikanWasTaken
Copy link

Helped a lot

@AlexParshh
Copy link

Lifesaver!

@gsuarez-sfdc
Copy link

it worked, thank you man!!!

@erbanku
Copy link

erbanku commented Feb 20, 2023

Unable to fix it on Ubuntu 22.04 LTS. So sad.

@pygman
Copy link

pygman commented Mar 31, 2023

Step 3 and Step 4 helpd me fix it on jetbrains ide, thank you.

@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 👍

@foxmean
Copy link

foxmean commented May 16, 2024

Thanks! I use MacBookAir M1 Machine and the modified version of this guide from @shaunsim15 works for me.

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