GPG Commit Signing for Git
Intermediatev1.0.0
Set up GPG commit signing with Git — key generation, Git configuration, GitHub verified badges, gpg-agent caching, and SSH signing as a modern alternative.
Content
Overview
GPG signing cryptographically proves that commits were authored by you, not someone impersonating your email. GitHub and GitLab show "Verified" badges on signed commits. Modern Git also supports SSH key signing as a simpler alternative.
Why This Matters
- -Verified identity — proves commits are genuinely from you
- -Compliance — required for SOC2, HIPAA, and regulated environments
- -Supply chain security — prevents commit impersonation
- -GitHub badges — green "Verified" label on signed commits
GPG Signing Setup
Step 1: Generate GPG Key
Step 2: Configure Git
Step 3: Add Key to GitHub
Step 4: Configure gpg-agent
SSH Signing (Simpler Alternative)
Setup SSH Signing
Verifying Signed Commits
Best Practices
- -Use SSH signing for simplicity (Git 2.34+, fewer tools)
- -Use GPG signing for compliance (established standard, key servers)
- -Set expiration dates — 1-2 years, extend before expiry
- -Cache passphrases with gpg-agent (8+ hours)
- -Match Git email with GPG key email exactly
- -Sign all commits with commit.gpgsign = true
Common Mistakes
- -GPG key email doesn't match git user.email (commits unverified)
- -No passphrase caching (typing passphrase every commit)
- -Forgetting to add public key to GitHub (no verified badge)
- -Using GPG when SSH signing would be simpler
- -Key expiration not set (keys should rotate)
FAQ
Discussion
Loading comments...