Share your experience with the founderhere!

Nishil Patel
May 8, 2024
5 min read
Last Updated Mar 11, 2026
The “error: gpg failed to sign the data” error can sometimes throw you off guard when you try making GPG-signed commits with Git. This article describes the potential causes of the gpg error and ways to identify and fix it for Windows/Linux/MacOS.
1.
Introduction
2.
What is the GPG Key in Git?
3.
How to Fix “Error: Gpg Failed to Sign the Data” Error in Git: For Windows/Linux/MacOS
4.
FAQs
Sometimes, you might get the “error: gpg failed to sign the data” message while creating a code commit using Git with a GPG signature. It indicates a problem with the GPG signing process. Luckily, you can fix the error with just a few commands.
Here’s what the error typically looks like when you try to make a GPG-signed commit that uses an erroneous GPG key (or a misconfigured environment):
git commit -m "message"
error: gpg failed to sign the data
fatal: failed to write commit objectAlso Read: How to Debug Using AI with BetterBugs MCP and VS Code: Easy Steps
GnuPG or GPG keys are used to authenticate commits and tags while managing code using Git. It’s a cryptographic signature that guarantees that code changes originate from a trusted source. Here’s what the GPG key does:
While GPG remains the legacy standard, recent versions of Git now also support using SSH keys or S/MIME for commit signing, which you may find easier to configure than GPG.
Also Read: GiHub vs. GitLab
Here’s how to figure out what’s wrong and fix the “error: gpg failed to sign the data” error:
Run the following command in your git-enabled terminal to get details about Git logs:
GIT_TRACE=1 git commit -m "message"This sets the “GIT_TRACE” env variable value to 1. Running the command tells Git to print out detailed trace information about the internal process during the commit.
After running the command, you usually get a message with the last few lines looking something like:
10:12:21.123456 run-command.c:688 trace: run_command: gpg --status-fd=2 -bsau <your GPG key>
error: gpg failed to sign the data
fatal: failed to write commit object
The message means there’s a problem with your GPG key or your terminal's ability to prompt you for a password. And the error occurred right after Git tried to run this command: “gpg --status-fd=2 -bsau <your GPG key>”
Next, run the following command for more details about the issue and get to the root cause of the error.
gpg --status-fd=2 -bsau <your GPG key>For instance, if you run the command “gpg --status-fd=2 -bsau ABCD1234” with a GPG key that is not set or unavailable, here’s what the output looks like:
gpg: skipped "ABCD1234": No secret key
[GNUPG:] INV_SGNR 9 ABCD1234
[GNUPG:] FAILURE sign 17
gpg: signing failed: No secret keyThese can include:
Also Read: How to Fix JavaScript Heap Out of Memory? Step-by-Step
To make sure that your GPG key is problematic (and to test if your terminal can successfully ask for your password), diagnose the issue by running the following command:
echo "hello" | gpg -bsau <your GPG key>Output (if the key is bad):
gpg: skipped "<your GPG key": Unusable secret key
gpg: signing failed: Unusable secret keyThis command tries to sign the data “hello” with “<your GPG key>”, which is unusable, expired, or may have other issues. Hence, the incorrect response.
Also Read: chrome://net-internals/#dns: How to Clear DNS Cache on Chrome
Here are the steps to fix the issue based on your OS:
Windows issues usually arise because Git for Windows has a built-in GPG program that clashes with the “Gpg4win software” you may have installed. Here’re the steps to fix it:
1 - Get the list of available keys
gpg --list-secret-keys --keyid-format=long2 - Configure Git to use your chosen key
git config --global user.signingkey <your GPG key>3 - Explicitly tell Git where the correct Windows GPG executable is located (usually installed via Gpg4win)
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"4 - Enable auto-signing
git config --global commit.gpgsign trueThe above steps should resolve the GPG error. If the GPG is unavailable or not set properly, you can create a new GPG key, set the key, and then try to proceed with your commit process.
Also Read: How to Fix Error Code: Out of memory in Chrome: Top 10 Ways + Easy Steps
The most common issue on Linux is that GPG doesn't know which terminal to use to ask for your password. Here’re the steps to fix the Gpg issue on Linux:
1 - Get the list of available keys:
gpg --list-secret-keys --keyid-format=long2 - Configure Git to use your chosen key:
git config --global user.signingkey <your GPG key>3 - Tell GPG which terminal (TTY) to use. Add this line to your ~/.bashrc or ~/.zshrc file:
export GPG_TTY=$(tty)4 - Restart your terminal or run the following command:
source ~/.bashrc5 - Run the following to enable Git to sign all commits by default:
git config --global commit.gpgsign true1 - Ensure GPG is installed via Homebrew
brew install gnupg pinentry-mac2 - Configure GPG to use the Mac UI
For Apple M-Series
echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.confFor Intel Macs
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf3 - Set the global path for GPG based on your Mac's processor:
For Apple M1/M2/M3/M4/M5
git config --global gpg.program /opt/homebrew/bin/gpgFor Intel Macs
git config --global gpg.program /usr/local/bin/gpg4 - Add the TTY export to your “~/.zshrc” file
export GPG_TTY=$(tty)5 - Reload the GPG agent so it picks up the new configuration by running the following command
gpgconf --kill gpg-agent6 - Restart the terminal for the changes to take effect.
7 - To list available keys, run the following command
gpg --list-secret-keys --keyid-format=long(If needed, generate a new key using “gpg --full-generate-key”)
8 - Set the global signing key
git config --global user.signingkey <your GPG key>9 - Configure Git to sign all commits by default
git config --global commit.gpgsign trueThere you go! With the steps above and considering your specific OS setup, you should be able to fix the GPG error.
Nishil is a successful serial entrepreneur. He has more than a decade of experience in the software industry. He advocates for a culture of excellence in every software product.
Meet the Author: Nishil Patel, CEO, and Co-founder of BetterBugs. With a passion for innovation and a mission to improve software quality.
We never spam.