Git error - gpg failed to sign data
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
gpg failed to sign data is a Git-side symptom, not the root cause. Git asked GPG to sign the commit or tag, and GPG could not complete the operation because of a missing key, a bad gpg-agent setup, a broken terminal configuration, or a mismatched Git config.
The fastest way to fix it is to test GPG outside Git first. Once plain GPG signing works, Git signing usually works too.
Diagnose the Real Failure
Start by checking whether your secret key is present and whether GPG can use it.
If the second command fails, the issue is in GPG itself, not in Git. Typical causes include:
- No secret key exists on this machine.
- The configured signing key is wrong.
- '
gpg-agentis not running correctly.' - '
pinentrycannot open a prompt.' - The terminal session does not expose
GPG_TTY.
Next, inspect Git’s signing-related configuration.
If user.signingkey does not match one of the secret keys shown by GPG, Git is asking for the wrong key.
A Working Setup
A common minimal setup on macOS or Linux looks like this:
Then restart the shell or reload the profile:
After that, test again:
If the commit succeeds, the chain from Git to GPG to the agent is working.
Why GPG_TTY Matters
In terminal-based workflows, GPG often needs pinentry to ask for the private key passphrase. Without GPG_TTY=$(tty), the prompt may have nowhere valid to attach, so Git only reports a generic signing failure.
That is why the same key can appear valid when listed with gpg --list-secret-keys, but signing still fails inside a shell session. Listing keys does not require passphrase entry; signing does.
GUI environments can have similar issues if Git runs in one environment and GPG expects another. In that case, explicitly setting gpg.program and restarting gpg-agent is often necessary.
Expired or Unusable Keys
If the key exists but has expired, Git signing will still fail. Check the expiration date with:
If needed, update the key:
Then use the expire command inside the interactive prompt and save the changes.
Also confirm that the key has signing capability. Some keys are created with subkeys, and Git may need the signing subkey rather than the primary key ID depending on how your environment is configured.
Common Pitfalls
One common mistake is importing only the public key. Git signing requires the secret key. If gpg --list-keys shows the key but gpg --list-secret-keys does not, signing cannot work.
Another pitfall is mixing GPG versions or binaries. On some machines, Git points at a different GPG executable than the one you tested manually. Check git config --get gpg.program and which gpg.
Developers also often forget that IDEs may launch Git in a different environment from the terminal. A commit that signs correctly in Terminal can still fail in an editor-integrated Git client if the agent or pinentry is not available there.
Finally, do not debug only from Git’s top-level error message. Run GPG commands directly and inspect the lower-level failure.
Summary
- '
gpg failed to sign datausually means GPG, the agent, or Git config is misconfigured.' - Verify plain GPG signing outside Git first.
- Make sure
user.signingkeymatches a real secret key. - Set
GPG_TTY=$(tty)in terminal workflows and restartgpg-agent. - Check for expired keys, wrong binaries, and IDE-specific environment mismatches.
Related reading
- git error failed to push some refs to remote
- Git error failed to push some refs to remote
- Git Error fatal invalid branch name init.defaultBranch
- Git error fatal unable to connect a socket Invalid argument
- Git error Host Key Verification Failed when connecting to remote repository
- Git error on git pull unable to update local ref
- Git error on commit after merge - fatal cannot do a partial commit during a merge
- Git error Please make sure you have the correct access rights and the repository exists
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.