Today, I need to commit some pieces of stuff to my GitHub repository, but somehow this error comes I don’t know.
It’s really painful.
error: gpg failed to sign the data fatal: failed to write commit object
After some researches on Google, I know that Github has implemented something called GPG to sign and verify work from trusted collaborators, using public-secret key mechanism. (refer: https://help.github.com/articles/signing-commits-with-gpg/)
So, to solve the problem, I have to config gpg to be able to sign commits. Note that from now, I will use brew to manage my installations. To install and know more about brew, you could go through its homepage: https://brew.sh
Homebrew installs packages to their own directory and then symlinks their files into
1. We need pinentry to read passphrases and PIN numbers in a secure manner. (For more information: https://www.gnupg.org/related_software/pinentry/index.en.html)
~/W/G/TalentHub-solutions ❯❯❯ brew install pinentry-mac
2. We need gpg of course, I use gpg2
~/W/G/TalentHub-solutions ❯❯❯ brew install gpg2
3. Now we are ready to generate our secret key, I chose all by default.
~/W/G/TalentHub-solutions ❯❯❯ gpg --gen-key
4. Once you have a private key to sign with, you can configure Git to use it for signing things by setting the user.signingkey config setting.
4.1. Get your secret key:
~/W/G/TalentHub-solutions ❯❯❯ gpg --list-secret-keys
You will see something like:
Then, B069A034 is your secret key.
4.2. Config your signing key:
~/W/G/TalentHub-solutions ❯❯❯ git config --global user.signingkey B069A034 ~/W/G/TalentHub-solutions ❯❯❯ git config --global gpg.program gpg ~/W/G/TalentHub-solutions ❯❯❯ git config --global commit.gpgsign true
5. Point out the pinentry program to gpg-agent.conf:
~/W/G/TalentHub-solutions ❯❯❯ touch ~/.gnupg/gpg-agent.conf ~/W/G/TalentHub-solutions ❯❯❯ echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
Now you will be able to commit to your git repository.
~/W/G/TalentHub-solutions ❯❯❯ echo "no-tty" >> ~/.gnupg/gpg.conf