🔀 The Signing Key Git Doesn’t Know You Replaced
Git’s commit signing reads the key to use from user.signingkey, and that setting is a literal key fingerprint, not a reference to whichever key GPG currently considers default. Generating a new GPG key or letting an old one expire doesn’t update that setting automatically, so git commit -S keeps trying to sign with the fingerprint Git was told about originally, which may no longer exist in the local keyring at all, and fails with a GPG-level error that gives no hint the problem is a stale Git config setting rather than anything wrong with the new key itself.
🔎 The Problem
# A new GPG key was generated after the old one expired... gpg --list-secret-keys --keyid-format=long # sec rsa4096/A1B2C3D4E5F6A7B8 2026-01-15 [SC] # ...but Git's signing config still points at the OLD fingerprint, # which this keyring no longer has a secret key for: git config --get user.signingkey # 9F8E7D6C5B4A3210 git commit -S -m "Fix pagination bug" # error: gpg failed to sign the data # fatal: failed to write commit object # (The real cause: GPG can't find a secret key for 9F8E7D6C5B4A3210 # at all - it's not that the NEW key is broken, Git was never told # to use it.) # Point Git at the new key's fingerprint: git config --global user.signingkey A1B2C3D4E5F6A7B8 git commit -S -m "Fix pagination bug" # now signs successfully
✅ Fix: Point Git at the Fingerprint You’re Actually Using
- After generating, importing, or switching to a new signing key, immediately update user.signingkey (and the SSH signing key setting if signing via SSH keys instead of GPG) to the new key’s fingerprint, since Git never discovers a new default key on its own.
- When git commit -S fails right after a key rotation, run gpg –list-secret-keys –keyid-format=long and compare the fingerprint against git config –get user.signingkey before assuming the new key itself is misconfigured or that GPG is broken.
- If multiple machines or team members share signing configuration through dotfiles or a provisioning script, update the signing key reference there too, so a key rotation doesn’t leave some clones pointed at a fingerprint that no longer has a matching secret key anywhere.
⚠️ Why This Is Easy to Miss
- GPG’s error message is generic enough to suggest a GPG agent problem or a broken keyring, and none of the obvious first troubleshooting steps, restarting gpg-agent, re-entering a passphrase, touch the actual cause, which is a single stale fingerprint sitting in Git’s own config.
- The old key often still appears in gpg –list-keys, since public and expired keys aren’t necessarily deleted, so a quick glance at ‘do I have a signing key’ says yes, while the specific question that actually matters, does the keyring have a secret key matching the exact fingerprint Git is configured to use, goes unchecked.
Git doesn’t sign commits with ‘your GPG key’ – it signs them with the one fingerprint you told it about, and a new key doesn’t become that fingerprint just because it’s newer.

