Sub topic 8
Verifying GPG Signatures and Understanding Trust
This chapter assumes you can already sign a commit with a GPG key and that you know the basics of public and private keys. Here you will check signatures on commits and tags, and learn why a valid signature can still carry a warning.
Two separate questions
Verification answers two questions that are easy to confuse.
- Is the signature mathematically valid? Does the signed data match the signature, and was it made by the key it names?
- Do you trust that key to belong to the person it claims to represent?
GnuPG answers the first question from the data alone. The second depends on your local keyring and on the trust you have assigned there. A signature can be valid and still show a warning.
Verifying commits and tags
Git provides three ways to check a signature.
git log --show-signature -1
git verify-commit HEAD
git tag -v v1.0.0git log --show-signature prints the signature check beneath each commit it lists. git verify-commit checks one commit and prints the GnuPG output. git tag -v does the same for a signed tag. These commands exit with a non-zero status when verification fails, so you can use them in scripts.
A typical result for a key you have not certified looks like this:
gpg: Signature made Fri 04 Dec 2026 15:30:12 UTC
gpg: using EDDSA key 3AA5C34371567BD2
gpg: Good signature from "Alice <[email protected]>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner."Good signature" is the answer to the first question. The warning is the answer to the second.
Getting the public key first
You can only verify a signature if the signer's public key is in your keyring. If it is missing, GnuPG reports Can't check signature: No public key. Import the key from a file or a keyserver.
gpg --import alice-public.asc
gpg --list-keys --keyid-format=longTake the key from a source you can check, such as the person directly or a hosting profile. Fetching a key by ID from a keyserver proves nothing about who owns it.
How trust works
GnuPG uses a web of trust model. Each key in your keyring has a validity, which means how sure you are that it belongs to the named person. Validity comes from two places: keys you have certified yourself, and keys certified by others whom you trust. The validity shown in brackets after "Good signature" can be unknown, marginal, full, or ultimate.
To raise a key from unknown, compare its fingerprint with the owner through a channel you trust, then sign it locally.
gpg --fingerprint [email protected]
gpg --lsign-key [email protected]--lsign-key makes a certification that stays on your machine. Use it instead of --sign-key, which creates an exportable certification that vouches for the key publicly.
You can also set owner trust with gpg --edit-key [email protected] followed by the trust command. Owner trust says how far you rely on that person to certify other keys. It does not make their own key valid.
What a good signature does not tell you
A good signature shows that the holder of a private key signed this exact content. It does not show that the signer is the person named in the commit's author field. Git checks nothing about that link, and the author name is free text. Confirm that the email in the key's user ID matches the identity you expect.
The signature also does not show that the key was still valid and uncompromised when you check it. GnuPG flags expired and revoked keys, for example with Good signature from ... [expired] or a revocation warning. Treat those as failures to investigate.
Scripting the check
To make a script fail on unsigned or unverifiable commits, rely on the exit status.
for c in $(git rev-list origin/main..HEAD); do
git verify-commit "$c" || { echo "Unverified: $c"; exit 1; }
doneNote that git verify-commit succeeds for a good signature even when validity is unknown. If you need stricter rules, inspect the output of git log --format='%H %G?'. The %G? placeholder prints G for good, U for good with unknown validity, B for bad, X for expired, R for revoked, E for unverifiable, and N for no signature.
Exercise
A teammate's commit shows "Good signature from "Bob <[email protected]>" [unknown]" and "This key is not certified with a trusted signature". The signature is valid, so why is there a warning, and how do you remove it correctly?
Show answer
The signature check passed, but your keyring has no certification linking the key to Bob. To remove the warning, compare the key's fingerprint with Bob over a trusted channel, then run gpg --lsign-key [email protected]. Changing owner trust alone would not make his key valid.
Exercise
Which %G? code does a good signature from a key with unknown validity produce, and why does git verify-commit still exit with success?
Show answer
It produces U. git verify-commit succeeds because the signature is cryptographically good, and Git only fails when GnuPG reports a bad or unverifiable signature.