Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Git

Git: Fix a Commit Signing Failure That Only Happens After Switching to a New GPG Key

- 10.10.26 - ErcanOPAK

🔀 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.

— Version Control Tip

Related posts:

Git: Fix a Conditional includeIf Config Block That's Silently Ignored Because the gitdir Pattern Doe...

Git: Fix a Conditional includeIf Config Block That's Silently Ignored Because the gitdir Pattern Doe...

Git: Automating Code Quality with Client-Side Git Hooks

Git: Automating Code Quality with Client-Side Git Hooks

Git: Fix a Merge Driver Defined in .gitattributes Never Running Because It Wasn't Also Registered in...

Git: Fix a Merge Driver Defined in .gitattributes Never Running Because It Wasn't Also Registered in...

Views: 10

Post navigation

Windows 11: Fix a Virtual Desktop Switch That Silently Resets Every Open Window Back to Its Default Position
Visual Studio: Fix a CodeLens Reference Count That Shows Zero Callers for a Method You Can Clearly See Being Called

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com