error: gpg failed to sign the data (Git) — how to fix
error: gpg failed to sign the data
fatal: failed to write commit object
Quick fix: Run export GPG_TTY=$(tty) (add it to ~/.bashrc or ~/.zshrc) and gpgconf --kill gpg-agent, then test with echo test | gpg --clearsign. Check that git config user.signingkey matches a key from gpg --list-secret-keys --keyid-format=long. To commit without signing once: git commit --no-gpg-sign.
What it means
When commit.gpgsign (or tag.gpgsign) is on, Git runs gpg to sign each commit. Git doesn't show gpg's actual error, it only reports that signing failed. Get the real message first:
GIT_TRACE=1 git commit -m "test" # shows the exact gpg command Git runs
echo test | gpg --clearsign # same operation, with gpg's own error
If the gpg --clearsign test fails, the problem is in GnuPG, not Git.
Cause 1: gpg can't prompt for the passphrase
The most common case. gpg-agent needs a terminal or a pinentry program to ask for the passphrase, and doesn't know which terminal you're on. The test prints something like gpg: signing failed: Inappropriate ioctl for device.
Fix 1
export GPG_TTY=$(tty)
gpgconf --kill gpg-agent # restarts the agent on next use
Add the export GPG_TTY=$(tty) line to ~/.bashrc or ~/.zshrc so it is set in every shell.
On macOS, GUI apps and IDEs can't use the terminal prompt. Install a graphical pinentry and point the agent at it:
brew install pinentry-mac
echo "pinentry-program $(brew --prefix)/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent
Cause 2: the signing key is missing or wrong
user.signingkey points at a key that isn't in your keyring (e.g. after moving to a new machine), or no key exists for your commit email. gpg prints gpg: skipped "...": No secret key.
Fix 2
gpg --list-secret-keys --keyid-format=long
# sec ed25519/3AA5C34371567BD2 2025-01-10 [SC]
git config --global user.signingkey 3AA5C34371567BD2
The key's user ID email should match git config user.email, otherwise GitHub/GitLab will show the commit as unverified. If you have no key at all, create one with gpg --full-generate-key, or turn signing off (Fix 4).
Cause 3: the key has expired
gpg refuses to sign with an expired key. gpg --list-secret-keys shows [expired: ...].
Fix 3
Extend the expiry date instead of making a new key:
gpg --edit-key 3AA5C34371567BD2
gpg> expire
gpg> save
Then upload the updated public key to GitHub/GitLab again (gpg --armor --export 3AA5C34371567BD2).
Cause 4: signing is on but you don't want it
A dotfile or company setup turned on commit.gpgsign, or the repo's local config does.
Fix 4
git commit --no-gpg-sign -m "message" # just this commit
git config --global commit.gpgsign false # stop signing
git config --show-origin --get commit.gpgsign # find where it's set
If a branch protection rule requires signed commits, you need a working key instead (Fixes 1-3), or the push will be rejected.
Cause 5: Git calls the wrong gpg binary
With several GnuPG installs (Git for Windows ships its own gpg), Git may use one whose keyring doesn't have your key.
Fix 5
git config --global gpg.program "$(command -v gpg)"
On Windows with Gpg4win, set it to the full path, e.g. "C:\Program Files (x86)\GnuPG\bin\gpg.exe".
Last updated 2026-11-30.