Signing commits and tags

Intermediate · 9 min

Prove who made a commit or tag by signing it with an SSH key, set up allowed signers, read the G, U and N statuses, and see what rewriting does to signatures.

Before thisTags and releasesObjects, blobs, trees and commitsConfiguration, aliases and attributes

The Modern SDE · 9 min

Signing commits and tags

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by The Modern SDEReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Anyone can set `user.name` and `user.email` to anything, so author fields prove nothing, and a signature proves the commit was made by someone holding a particular private key.
  • SSH signing needs `gpg.format ssh`, `user.signingkey` pointing at a public key, and `commit.gpgsign true` (and `tag.gpgsign true`) to sign automatically.
  • To verify, Git needs `gpg.ssh.allowedSignersFile` listing trusted email and key pairs, and without it verification reports an error and `%G?` shows `N`.
  • `git log --show-signature` and `git log --format='%G?'` report `G` (good), `U` (good signature, unknown signer) or `N` (no signature, or unverifiable).
  • Rewriting a signed commit creates a new commit, and the new one is signed only if signing is enabled, so rebases silently drop signatures unless `commit.gpgsign` is true.

Authorship is a claim

$ git -c user.name="Linus Torvalds" -c user.email=linus@example.com commit -m "Totally legit"

That works, and the log will show whatever name you typed. Git’s author and committer fields are plain text. On a team that is usually fine, but when you ship software people install, you want a stronger statement: “this commit was made by someone holding this key”. A signature is that statement. The commit object gets an extra signature block, and anyone with your public key can check it.

You can sign with GPG, S/MIME, or, since Git 2.34, an SSH key you already have for pushing. I used SSH, with a throwaway key made for this lesson (ssh-keygen -t ed25519 -N ""), on Git 2.54. I did not test GPG signing. The video’s lesson covers both.

Setting it up

$ git config gpg.format ssh
$ git config user.signingkey /path/to/key.pub
$ git commit -S -m "Signed commit"

-S signs one commit. To sign everything, and annotated tags too:

$ git config commit.gpgsign true
$ git config tag.gpgsign true

Now a surprise. I tried to look at the result straight away:

$ git log -1 --format='%h %G? %GS'
error: gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification
efdbf5f N

%G? is N, “no signature”, for a commit I had just signed. Signing needs only your private key, but verifying needs to know whom to trust, and Git has nowhere to look. Its answer was “I can’t verify”, reported as N, which is misleading. The cause is the missing allowed-signers file.

The allowed-signers file

Create a file with one line per trusted person: an email (or *), then their public key type and key:

ada@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5...
$ git config gpg.ssh.allowedSignersFile ~/.config/git/allowed_signers
$ git log -1 --show-signature
commit efdbf5f143a4...
Good "git" signature for ada@example.com with ED25519 key SHA256:9j+hvZAOZ1J1y6X1HHSffnuTNQERM3QH6N6pgT6hFqA
...
$ git log -1 --format='%h %G? %GS'
efdbf5f G ada@example.com
$ git verify-commit HEAD
Good "git" signature for ada@example.com with ED25519 key SHA256:...

G is good. Tags work the same way:

$ git tag -s v1.0 -m "First release"
$ git tag -v v1.0
Good "git" signature for ada@example.com with ED25519 key SHA256:...

(Hashes and fingerprints will differ for you.) On a team, the file would be committed to the repository or distributed, so everyone trusts the same keys.

The statuses

I created three situations: a signed commit, an unsigned one, and one signed by a different key that wasn’t in the file.

$ git log --format='%h %G? %s'
01fdaab U Signed by Mallory
c3426a0 N Unsigned
f748ef7 G Auto-signed
efdbf5f G Signed commit
Code Meaning
G good signature from a key in the allowed list
U cryptographically good, but the signer is not trusted
N no signature (or one Git couldn’t verify)

U for Mallory is the useful one. The signature is mathematically fine, and --show-signature said Good "git" signature with ED25519 key SHA256:23Y1... followed by No principal matched. A signature is only as good as your list of keys you trust. Check a merge with git merge --verify-signatures <branch>. I tried it with an unsigned commit on the branch: fatal: Commit 424ac00 does not have a GPG signature. (The message says GPG even for SSH.)

Rewriting drops signatures

A signature covers a specific commit, hash and all. Any rewrite creates a new commit that needs a new signature. I rebased a signed commit with commit.gpgsign unset:

$ git rebase main
Successfully rebased and updated refs/heads/topic.
$ git log --format='%h %G? %s'
62bbcd8 N three
6e38c44 G four

The rebased commit three lost its signature (N). With commit.gpgsign true, a rebase of another branch re-signed the replayed commit (G). That is one more reason to enable automatic signing, rather than rely on -S each time, if you rebase. Remember that a signature by you after the rebase says you made the rewritten commit. It doesn’t preserve the original author’s signature.

What signing proves, and what it doesn’t

It proves the commit was created by a holder of the key, and wasn’t altered afterwards. It doesn’t prove the code is safe, or that the key belongs to the right person unless you verified it independently. Hosting services show a “Verified” badge when a commit’s signature matches a key registered to the account, which I could not test here. Pair signing with authentication and SSH keys on the hosting side, and with branch rules that can require signed commits.

What the video covers

The Modern SDE’s “Git Signed Commits and Tags: SSH and GPG Signatures, Verified on GitHub” is lesson 59 of a series, about nine minutes, from late 2026. From its title it covers signing both commits and tags with both key types, and showing the badge on a hosting service. I judge English from the title, description and channel only, and I could not read a transcript. Nick Janetakis’ longer 2020 video covers GPG in detail and is linked as a runner-up. That channel appears three times in this group, and the series is new, so treat its quality as unconfirmed.

Where this fits

That closes the advanced repositories group, and with it Agent B’s part of the roadmap. Next, the team workflows built on all this: trunk-based development.

Check yourself

  1. 01Why isn't the author name in a commit evidence of who wrote it?

    It is whatever `user.name` and `user.email` were set to, which anyone can change. Only a signature ties a commit to a private key.

  2. 02What are the three config settings needed to sign commits with an SSH key?

    `gpg.format ssh`, `user.signingkey` set to the public key file, and `commit.gpgsign true` to sign every commit. `-S` signs a single commit instead.

  3. 03`git log --format=%G?` shows `U`. What does it mean?

    The signature is cryptographically valid but the key isn't in your allowed-signers file, so Git can't map it to a trusted person.

  4. 04You rebase a branch of signed commits and they show `N` afterwards. Why?

    A rebase makes new commits, and signing happens only when `commit.gpgsign` is true or you pass `-S`. The old signatures belonged to the old commits.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark