Signed Commits (GPG/SSH)
Learn to sign Git commits with GPG or SSH keys, verify the signed object locally, and understand how hosting platforms decide whether to show a verification status.
A Git signature associates a signing key with a specific commit object and lets a verifier detect changes to that object. It does not prove the key holder's legal identity, author intent, or code review status. Local verification uses a configured keyring or allowed signers file; hosting platforms apply their own key-registration and account rules before displaying a status. This guide covers GPG and SSH setup, rewriting signed commits, and key rotation and revocation.
Introduction
Git lets you set the author and committer names and emails in commit metadata; those fields do not authenticate a person. A GPG or SSH signature answers a narrower question: did the private key corresponding to this public key sign this commit object, and has the object changed since?
Local tools verify against a keyring or allowed signers file. Hosting platforms use their own registration and account rules to decide whether to show a status such as “Verified.” A badge is a platform result for a key and commit, not a complete identity or review record. This guide covers GPG and SSH setup, verification, and key lifecycle.
When to Use / When Not to Use
When to sign commits:
- Open source projects where identity matters
- Enterprise repositories with compliance requirements
- Supply chain security for critical software
- Regulated industries (finance, healthcare, government)
- Repositories whose documented policy requires signed commits
When signing may be optional:
- Personal projects with single contributors
- Internal tools with trusted teams
- Rapid prototyping where overhead outweighs benefit
Core Concepts
Git supports two signing methods:
graph TD
COMMIT["Commit Object"] -->|signs with| KEY["Cryptographic Key"]
KEY --> GPG["GPG/PGP Key\n(traditional)"]
KEY --> SSH["SSH Key\n(modern, simpler)"]
GPG --> SIG1["GPG Signature\nin commit header"]
SSH --> SIG2["SSH Signature\nin commit header"]
SIG1 --> VERIFY1["Verify with GPG\npublic key"]
SIG2 --> VERIFY2["Verify with SSH\npublic key"]
VERIFY1 --> TRUST1["Local verifier policy"]
VERIFY2 --> ALLOW["Allowed signers\nor platform policy"]
Both methods embed a cryptographic signature in the commit object. The signature covers the object contents, including its tree, parents, author and committer metadata, and message. Changing any of those fields changes the object and invalidates that signature. The signature identifies a key; a separate policy is needed to associate that key with an account or person.
Architecture or Flow Diagram
flowchart LR
DEV["Developer"] -->|creates| COMMIT["Commit Object"]
COMMIT -->|signs with| KEY["Private Key\n(GPG or SSH)"]
KEY -->|produces| SIG["Signature Block\nembedded in commit"]
SIG -->|pushed to| PLATFORM["GitHub/GitLab"]
PLATFORM -->|applies its rules to| PUBKEY["Registered public key\nand account metadata"]
PUBKEY -->|result| BADGE["Platform status\n(policy dependent)"]
AUDITOR["Auditor"] -->|runs| VERIFY["git verify-commit"]
VERIFY -->|checks| LOCALKEY["Local Keyring\nor allowed signers"]
Step-by-Step Guide / Deep Dive
GPG Signing Setup
1. Generate a GPG key:
# Generate a new GPG key (interactive)
gpg --full-generate-key
# Or non-interactive for scripting
gpg --batch --gen-key << EOF
%no-protection
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: Your Name
Name-Email: your.email@example.com
Expire-Date: 0
%commit
EOF
2. Configure Git to use it:
# List your GPG keys
gpg --list-secret-keys --keyid-format=long
# Configure Git (use the key ID from above)
git config --global user.signingkey ABC123DEF456
git config --global commit.gpgsign true
# Optional: sign tags too
git config --global tag.gpgsign true
3. Add your public key to GitHub/GitLab:
# Export your public key
gpg --armor --export ABC123DEF456
# Copy the output and add it to:
# GitHub: Settings → SSH and GPG keys → New GPG key
# GitLab: Settings → GPG Keys
SSH Signing Setup (Git 2.34+)
SSH signing is supported by Git 2.34 and later. You can use an existing SSH key, though some teams keep signing and authentication keys separate.
Local SSH verification uses an allowed signers file that maps identifiers to public keys. A hosting platform has its own registration and account rules; a local allowed signer does not establish that the key belongs to a particular person on the platform.
# Configure Git to use SSH signing
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
# Create an allowed signers file
cat > ~/.gitallowed << EOF
your.email@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...
EOF
# Tell Git where to find it
git config --global gpg.ssh.allowedSignersFile ~/.gitallowed
gpg.format ssh switches Git to SSH-style signature headers. user.signingkey names your public key file. When you sign, Git finds the matching private key in your SSH agent. Ed25519 keys sign fast enough that you will not notice the overhead.
Signing Existing Commits
You may need to sign commits that are already there. Maybe you inherited a repo full of unsigned history, or maybe you finally set up signing on an old machine. Either way, signing a committed change means creating a new commit object with a new hash. That is what rewriting history means, and it requires a force-push.
Re-signing the last commit is easy: git commit --amend -S keeps the message and author info, just adds the signature. For a few specific commits, use interactive rebase and mark each one with edit, then amend them one by one. For bulk re-signing across a whole branch, git rebase -x 'git commit --amend --no-edit -S' applies the amend to every picked commit.
# Re-sign the last commit
git commit --amend --no-edit -S
# Re-sign multiple commits (interactive rebase)
git rebase -i HEAD~5
# Mark commits with 'edit', then:
git commit --amend --no-edit -S
git rebase --continue
# Sign all commits on a branch
git rebase main --exec 'git commit --amend --no-edit -S'
Force-pushing shared branches without talking to your team first is a good way to lose friends. Branch protection rules that require signed commits will block the push if even one commit in the range lacks a signature. Play it safe: re-sign in a feature branch, then merge onto protected branches through a signed commit.
Verification
# Verify the last commit
git log --show-signature -1
# Verify a specific commit
git verify-commit <sha>
# Show signature status in log
git log --format="%H %G? %GS" -10
# %G? = signature status (G=good, B=bad, U=untrusted, N=no signature)
# %GS = signer information
Production Failure Scenarios
| Scenario | Symptoms | Mitigation |
|---|---|---|
| Expired GPG key | Signing or verification reports expiry | Check local and host rules; renew or replace the key as policy requires |
| Missing key on platform | Platform cannot verify the key | Follow that host’s key-registration steps |
| SSH signing not supported | “error: unsupported value for gpg.format” | Upgrade Git to 2.34+ |
| Key rotation | Verification status depends on host policy | Register the new key; retain old public keys only while trusted |
| CI/CD signing | Automated commits unsigned | Use bot keys or disable signing for CI |
Trade-off Analysis
| Aspect | GPG | SSH |
|---|---|---|
| Setup complexity | Higher (key generation, keyring) | Lower (reuse existing SSH key) |
| Platform support | Check current host support and signing-key rules | Git 2.34+ locally; check host support and registration rules |
| Key management | GPG keyring, web of trust | SSH keys, allowed signers file |
| User familiarity | Less common among developers | Widely understood |
| Expiry handling | Built-in expiry dates | No expiry (manage manually) |
Implementation Snippets
# Enable signing for all commits
git config --global commit.gpgsign true
# Sign a single commit
git commit -S -m "Signed commit"
# Sign a tag
git tag -s v1.0 -m "Release 1.0"
# Verify all commits in a range
git log --show-signature v1.0..v2.0
# Check if commits are signed
git log --format="%H %G?" main
# Configure GUI tools to sign
git config --global gpg.program $(which gpg)
# Use specific GPG home directory
git config --global gpg.minTrustLevel ultimate
Observability Checklist
- Monitor: Percentage of signed commits in repository
- Verify: Platform status reflects its current key and account policy
- Track: Key expiry dates (set calendar reminders)
- Audit: Run
git log --show-signatureon release branches - Alert: Unsigned commits on protected branches
Security & Compliance Considerations
- A signature shows that a key signed a specific commit object; it does not establish the key holder’s legal identity or intent
- GPG keys should be stored securely (consider hardware tokens like YubiKey)
- SSH keys for signing should be separate from authentication keys
- Rotate keys periodically and update platforms
- See Git Secrets Management for comprehensive security
Common Pitfalls / Anti-Patterns
- Assuming key expiry or revocation works the same everywhere — check the local verifier and hosting platform behavior
- Not backing up GPG keys — losing your key means losing your identity
- Using weak algorithms — prefer RSA 4096 or Ed25519
- Signing in CI/CD without key management — exposes private keys
- Assuming signed = reviewed — signing does not establish review status or code quality
Quick Recap Checklist
- GPG signing requires a key and local verification setup; platform status has separate registration rules
- SSH signing (Git 2.34+) reuses existing SSH keys
- Configure
commit.gpgsign truefor automatic signing - Verify with
git log --show-signature - A platform may display a verification status when its checks pass
- Keep keys secure and backed up
- Rotate keys before expiry
Commit Signing Flow (Clean Architecture)
graph TD
DEV["Developer"] -->|1. writes| COMMIT["Commit Object"]
DEV -->|2. signs with| PRIVKEY["Private Key\nGPG or SSH"]
PRIVKEY -->|3. produces| SIG["Signature\nembedded in commit"]
SIG -->|4. pushed to| PLATFORM["GitHub / GitLab"]
PLATFORM -->|5. checks registration and policy| PUBKEY["Public Key\nand account metadata"]
PUBKEY -->|6. result| BADGE["Platform status\n(varies by host)"]
VERIFY["Local Verification"] -->|git verify-commit| RESULT["Good / Bad / Untrusted"]
RESULT -->|checks against| KEYRING["Local Keyring\nor allowed signers"]
Production Failure: Key Lifecycle Issues
Scenario: Expired GPG key breaking CI and verification
# Symptoms
$ git commit -S -m "Add feature"
error: gpg failed to sign the data
fatal: failed to write commit object
$ git log --show-signature -1
# A verifier may report the key's expiry; platform status rules vary
# Root cause: GPG key has an expiry date that has passed
# Recovery steps:
# 1. Check key expiry
gpg --list-keys --keyid-format long
# Look for [expires: 2024-01-01]
# 2. Extend key expiry
gpg --edit-key YOUR_KEY_ID
> expire
# Set new expiry date (e.g., 2y for 2 years)
> save
# 3. Re-export and update platform
gpg --armor --export YOUR_KEY_ID
# Update on GitHub/GitLab with new public key
# 4. Re-sign affected commits (if any failed)
git commit --amend --no-edit -S
# === Key Revocation Scenario ===
# If key is compromised:
# 1. Generate revocation certificate (do this when creating key!)
gpg --gen-revoke YOUR_KEY_ID > revocation.crt
# 2. Import revocation
gpg --import revocation.crt
# 3. Upload revoked key to keyserver
gpg --keyserver keys.openpgp.org --send-keys YOUR_KEY_ID
# 4. Generate new key and update all platforms
# 5. Update platform and organization key records; verification results vary by host
Trade-offs: GPG vs SSH vs X.509 Signing
| Aspect | GPG | SSH | X.509 |
|---|---|---|---|
| Setup complexity | High (keyring, web of trust) | Low (reuse existing SSH key) | Very high (certificate authority) |
| Git version required | Any | 2.34+ | 2.34+ |
| Platform support | Check the current host’s key rules | Check the current host’s key rules | Check the current host’s key rules |
| Key management | GPG keyring, subkeys | SSH keys, allowed_signers file | PKI, certificate lifecycle |
| Expiry handling | Built-in expiry dates | No expiry (manual management) | Certificate validity period |
| Hardware support | YubiKey, smart cards | YubiKey, SSH agent | Smart cards, HSM |
| User familiarity | Low (most devs don’t know GPG) | High (every dev has SSH keys) | Low (enterprise IT only) |
| Best for | Open source, maximum compatibility | Modern teams, simplicity | Enterprise, compliance |
Security/Compliance: Key Management Best Practices
Key Generation:
- Use Ed25519 for SSH (or RSA 4096 minimum)
- Use RSA 4096 or Ed25519 for GPG
- Never use DSA (deprecated and weak)
Key Storage:
- Store private keys on hardware tokens (YubiKey) when possible
- Never store private keys in cloud sync (Dropbox, iCloud)
- Use separate keys for signing vs authentication
Key Rotation:
- Rotate keys on the schedule required by your organization; replace them promptly if a private key may be exposed
- Keep an old public key available for historical checks only while it remains trusted. Revoke compromised keys and update platform and verifier records.
Backup and Recovery:
- Export and encrypt GPG secret key:
gpg --export-secret-keys --armor > backup.asc - Store backup in encrypted offline storage (not cloud)
- Generate revocation certificate immediately after key creation
- Document key IDs and expiry dates in team wiki
Compliance Notes:
- A signing policy can support a code-provenance control; signing by itself does not satisfy a compliance framework
- For SBOM and supply chain compliance, combine with SLSA framework
- Key signing ceremonies may be required for regulated environments
- Maintain an audit trail of key rotations and revocations
Interview Questions
A valid signature shows that the corresponding private key signed a specific commit object and that the signed object has not changed. It does not by itself prove who controls the key, whether the author metadata is accurate, or whether anyone reviewed the change.
SSH signing can be simpler if you already use SSH keys, while GPG offers keyring and expiry features. Platform support changes, so check that your Git host accepts the signing format and the key-registration method your team plans to use.
Yes, but it rewrites history. Use git rebase -i with exec git commit --amend --no-edit -S to sign existing commits. This changes commit hashes, so you'll need to force-push. For shared branches, coordinate with your team to avoid conflicts.
GitHub checks the signature against a key registered to an account and applies its account and email rules. A signed commit may show as "Verified" when those checks pass; an unregistered or otherwise unverifiable signature has a different status. GitHub also stores a verification record when it verifies a commit, so a later key rotation or revocation does not necessarily change that historical status. See GitHub's current documentation for the exact rules.
Git stores the signature in the commit's GPG header fields (for GPG) or SSH signature header (for SSH). The signature covers the commit's content: tree hash, parent hash, author timestamp, committer timestamp, and message. Any modification to these fields invalidates the signature. The signature is stored as base64-encoded data in the commit object itself, viewable with git cat-file -p <sha>.
A commit signature shows that a key signed a specific commit object. A signed tag signs a tag object that points to a release target, often a commit. Either signature can be checked against a public key and verifier policy. Configure tag signing with git config --global tag.gpgsign true.
An expired key may prevent new signatures or produce an expiry warning in local verification. Hosting platforms handle existing verification records and key expiry according to their own rules; do not assume all old commits change to "Unverified." Renew or replace the key for future commits, then check the local verifier and platform status. Re-signing creates new commit objects and is not required just to change the key's expiry.
Yes. Use repository-level Git config instead of global: cd /repo && git config user.signingkey <key-id>. This allows different keys per repository. For more complex setups, use git config gpg.program to point to wrapper scripts that select keys based on directory or git configuration.
The Web of Trust is GPG's decentralized key validation system where keys can sign other keys, creating trust chains. For Git verification, platforms like GitHub use an explicit trust model — they trust keys you've uploaded directly. The web of trust matters more for email encryption where you may encounter keys from key servers. For Git signing, explicit platform registration is sufficient.
Ed25519 is the recommended SSH key type for signing. Generate with: ssh-keygen -t ed25519 -C "git-signing@example.com". Configure Git: git config --global gpg.format ssh, git config --global user.signingkey ~/.ssh/id_ed25519.pub. Create allowed signers file: echo "your@email.com ssh-ed25519 AAAA..." > ~/.gitallowed, then git config --global gpg.ssh.allowedSignersFile ~/.gitallowed.
Agent forwarding allows the local SSH agent (containing YubiKey-backed keys) to be accessed on remote machines. Security implications: remote machines can request signatures from your agent (potentially signing unexpected things), and traffic can be sniffed if agent forwarding is intercepted. Mitigation: use Confirm constraints on YubiKey to require physical button press, and limit forwarding to trusted machines only.
A protected-branch rule can require commits to meet the host's signature verification policy before they enter the branch. The exact key registration rules and who can override protection depend on the host and repository settings. Such a rule checks signatures; it does not establish that the key holder is the person named in commit metadata or that the change was reviewed.
For local checks, keep an old public key available while you still trust it and need to verify its signatures. Register the new key for future commits according to the platform's rules. Do not keep a compromised key trusted just to preserve a badge. Some hosts, including GitHub, retain verification records for commits they already checked; other platforms may handle rotation and revocation differently.
A GPG revocation certificate marks a key as revoked. Generate and store it securely when creating the key. If the private key is compromised, import the certificate into your keyring, update the platform and organization records, and notify the people who rely on that key. Do not assume a public keyserver alone will notify every verifier; follow the distribution process used by your team and platform.
A merge does not copy a signature from a commit being merged onto the merge commit. Existing commits keep their signatures if their objects are unchanged; a merge commit needs its own signature if your policy requires one. Rebase, amend, and squash create new commit objects, so signatures on the replaced objects do not apply to the rewritten commits. Sign the new objects if required by your policy.
Signing has negligible performance impact for most use cases. Ed25519 signatures are ~64 bytes and compute in under 1ms on modern hardware. RSA 4096 signatures are larger (~512 bytes) and may take 10-50ms on slower hardware. The main overhead is key access (YubiKey adds ~100ms per signature due to USB communication). For typical repositories with hundreds of commits, the total signing time is not noticeable.
Yes, cloud HSMs (AWS CloudHSM, Google Cloud KMS, Azure Key Vault) can store signing keys. Setup typically involves: configuring the cloud KMS to allow the compute instance, installing the KMS SDK/tooling, and pointing Git's GPG or SSH to use the cloud KMS for signing. This provides centralized key management, audit logs, and automatic key rotation. Downsides: requires cloud credentials on build machines and introduces external dependencies.
commit.gpgsign (or commit.gpgsign true) globally enables signing for all commits. commit.signature is an older, deprecated alias. The setting user.signingkey specifies which key to use. You can override global settings per repository or per command with -S (sign) or --no-gpg-sign (don't sign a specific commit).
Git embeds a signature in the commit object. Local tools verify it using a public key and their configured trust rules, such as a GPG keyring or SSH allowed signers file. A hosting platform performs its own checks, which can include key registration and account metadata, before showing a status. Follow the host's documentation; "Verified" is that platform's result, not a universal identity claim.
X.509 certificates are preferred in enterprise environments with existing PKI (Public Key Infrastructure). Benefits: centralized key lifecycle management through Active Directory or certificate authorities, automatic enrollment and renewal through corporate PKI, integration with smart card infrastructure already deployed, and compliance with regulatory frameworks that mandate X.509 for all cryptographic operations. However, X.509 signing in Git requires Git 2.34+ and has limited platform support (primarily GitLab enterprise).
Further Reading
Additional Resources
- GitHub: Managing commit signature verification
- Git commit messages — Author and committer fields are metadata, not identity checks
- GitLab: Signed commits
- GnuPG: Best Practices
- SSH.com: Ed25519 for SSH
- YubiKey: GPG Guide
Topic-Specific Deep Dives
YubiKey for Git Signing
Hardware tokens provide the strongest protection for private keys. YubiKey supports both GPG and SSH signing.
GPG with YubiKey:
# Ensure GPG recognizes the YubiKey
gpg --card-status
# Generate key on the YubiKey (takes ~2 minutes)
gpg --edit-card
> generate
# Choose 4096-bit RSA, set expiry, save
# Configure Git to use the card
git config --global gpg.program $(which gpg)
# Sign commits normally - key is on the hardware token
git commit -S -m "Signed with YubiKey"
SSH with YubiKey:
# YubiKey 5+ supports SSH agent forwarding
# Add to ~/.ssh/config:
Host github.com
ForwardAgent yes
# Configure Git for SSH signing with YubiKey
git config --global gpg.format ssh
git config --global user.signingkey /path/to/yubikey.pub
Important: The private key never leaves the YubiKey. If you lose it, you cannot recover the key — this is by design. Always generate a revocation certificate when setting up hardware tokens.
CI/CD Pipeline Integration
Signing commits in automated pipelines requires careful key management to avoid exposing private keys.
GitHub Actions:
name: Signed Commits
on: [push, pull_request]
jobs:
sign:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git config --global user.signingkey KEY_ID
- name: Set up Git
run: |
git config --global commit.gpgsign true
- name: Make changes
run: echo "changes" >> file.txt
- name: Commit and push
run: |
git add .
git commit -m "Automated signed commit"
git push
GitLab CI:
variables:
GIT_STRATEGY: clone
before_script:
- echo "$GPG_PRIVATE_KEY" | gpg --import
- git config --global commit.gpgsign true
- git config --global user.signingkey $GPG_KEY_ID
signed-commits:
script:
- echo "changes" >> file.txt
- git add .
- git commit -m "CI signed commit"
- git push
artifacts:
paths:
- file.txt
SSH signing in CI (GitHub Actions):
- name: Configure SSH signing
run: |
echo "$SSH_SIGNING_KEY" > signing_key
echo "your@email.com ssh-ed25519 KEY" >> ~/.gitallowed
git config --global gpg.format ssh
git config --global gpg.ssh.allowedSignersFile ~/.gitallowed
git config --global user.signingkey signing_key
chmod 600 signing_key
Security considerations for CI:
- Use separate signing keys for CI (not your personal key)
- Store private keys in encrypted secrets
- Rotate CI keys according to the organization’s policy, especially if runners or logs could expose them
- Consider using ephemeral compute (CI runners) that don’t persist after jobs
- For high-security environments, use temporary keys per pipeline run
Continue to Git Secrets Management for protecting sensitive data in repositories.
Conclusion
Signed commits let a verifier check that a particular key signed a particular commit object. Whether that key is tied to a person or account depends on local trust settings and the hosting platform’s rules. Use signing alongside review, access controls, and any required compliance process; a signature alone does not replace them.
Category
Related Posts
Git Secrets Management and Pre-commit Hooks
Preventing secrets from entering repositories using pre-commit hooks, secret scanning tools, and automated detection. Protect API keys, tokens, and credentials from accidental commits.
Removing Sensitive Data from Git History
Using git filter-repo, BFG Repo-Cleaner, and git filter-branch to scrub secrets, passwords, and credentials from Git history. Step-by-step remediation guide.
JVM Bytecode Verification: Type Checking and Stack Map Frames
A practical guide to JVM bytecode verification by class-file version, including type inference, StackMapTable frames, VerifyError debugging, and verification limits.