Sub topic 1
What a signature proves, and what it does not
Prerequisites
This chapter assumes you can make commits and tags, read git log output, and set values with git config. You should also know the basic idea of a public and private key: the private key signs, and the public key checks the result. No signing setup is needed yet. Later chapters cover creating keys and configuring Git.
The problem: identity in Git is self-declared
Every commit records an author and a committer, each with a name and an email address. Git takes these from user.name and user.email, and anyone can set them to any value.
git -c user.name="Alice Example" -c user.email="[email protected]" \
commit --allow-empty -m "Looks like Alice wrote this"
git log -1 --format="%an <%ae>"Anyone who can push to a repository could run this command, and the commit would show Alice as the author. Git does not check the claim. An unsigned commit proves nothing about who created it.
What a signature adds
A signature is a cryptographic value computed from the commit's contents and a private key. For a commit, the signed data is the commit object itself. That includes the tree, the parent commit IDs, the author and committer lines, the timestamps, and the message. Git stores the signature inside the commit object as a gpgsig header.
Anyone who has the matching public key can check two things:
- The data has not changed since it was signed. Changing any signed field changes the commit ID and invalidates the signature.
- The signature was made by someone who held the private key.
sequenceDiagramThe diagram below shows the flow.
What a signature does not prove
A valid signature has a narrow meaning. It says that some key signed this exact data. It does not say who owns the key, or that the content is safe.
| Question | Does a valid signature answer it? |
|---|---|
| Was the commit changed after signing? | Yes. Any change breaks the signature. |
| Was it signed by the holder of this key? | Yes. |
| Does this key belong to Alice? | No. You must bind the key to a person separately. |
| Is the code correct or free of malware? | No. A signed commit can contain a bug or a backdoor. |
| Was the key stolen or was the author coerced? | No. A thief with the key can sign as the owner. |
| Is the commit the latest one? | No. Signatures do not stop someone from replaying older signed history. |
The key-to-person binding is the part people most often skip. You establish it in one of these ways:
- GPG: you trust the key through a web of trust or by checking its fingerprint in person.
- SSH: you list the public key and the email it belongs to in an allowed signers file.
- A hosting platform: you upload the public key to an account, and the platform shows a Verified badge for matching commits.
Each method only moves the question to a different place. The platform badge, for example, means "signed by a key registered to this account", which is only as strong as the account's security.
Commits and tags are signed differently
A signed commit protects that one commit. Because each commit contains its parents' IDs, the signature indirectly covers the history behind it. You can still not assume that older commits were signed. Each commit carries its own signature, or none.
A signed annotated tag protects the tag object. It names a commit and says that the signer vouches for it as, for example, release v1.0.0. Tags are the usual way to mark releases, so signing them is the most common first step.
Git does not sign lightweight tags, because they are only references with no object of their own.
Deciding whether you need it
Signing helps most when other people rely on your commits or releases, or when your repository feeds an automated pipeline. It is weaker when no one checks the signatures. An unverified signature is just extra bytes. Plan to verify, or the effort protects nothing.
Exercise
A teammate says, "This commit has a valid signature, so the code in it is safe to merge." What is wrong with that statement, and what does the valid signature actually tell you?
Show answer
A valid signature only shows that the commit data is unchanged since signing and that it was signed by a holder of the matching private key. It says nothing about whether the code is correct or safe, and it does not say who owns the key unless the key has been linked to a person through trust, an allowed signers file, or a hosting account. Review the code as usual.