Sub topic 11
Signing and Verifying Tags
This chapter assumes you can create annotated tags and push them to a remote, and that you have a GitHub account. You do not need to know cryptography. You do need a signing key, which the chapter shows how to set up.
Why sign a tag
An annotated tag records a tagger name and email, but anyone can set those to any value. A signed tag adds a cryptographic signature made with your private key. Anyone with your public key can check that the tag came from you and that the tagged commit and message were not changed afterward.
Signing matters most for release tags. Users and build systems often trust a tag such as v1.2.0 as "the official release", and a signature backs that trust.
Set up a signing key
Git can sign with a GPG key or an SSH key. SSH signing is simpler if you already use SSH for GitHub. This setup uses an existing SSH key:
# Tell Git to sign with SSH keys instead of GPG
git config --global gpg.format ssh
# Point Git at your public key
git config --global user.signingkey ~/.ssh/id_ed25519.pubFor GPG, find your key ID with gpg --list-secret-keys --keyid-format=long and set user.signingkey to that ID.
Create and verify a signed tag
The -s option creates a signed annotated tag. The -v option verifies one.
# Create a signed annotated tag (requires a configured GPG or SSH signing key)
git tag -s v1.2.0 -m "Release 1.2.0"
# Verify the signature
git tag -v v1.2.0A signed tag is always annotated, so it needs a message. If you omit -m, Git opens your editor.
With GPG, git tag -v prints a "Good signature" line and the signer. With SSH signing, verification also needs a file that lists trusted keys:
# A file of "email key" lines for people you trust
git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signersWithout that file, git tag -v fails for SSH signatures even when the signature is valid, because Git has no list of keys to trust.
Common errors
- "gpg failed to sign the data": GPG cannot reach your key or its passphrase prompt. Check that the key ID is correct and that
gpg-agentis running. - "no signature found": The tag is lightweight or annotated but unsigned. Recreate it with
-s, or use a new tag name if it is already published. - Verification fails on another machine: The verifier lacks your public key (GPG) or the allowed signers file (SSH). Share the public key through a trusted channel.
Exercise
Exercise
You run git tag -s v2.0.0 on a machine that uses SSH signing. Signing works, but git tag -v v2.0.0 fails. What is the likely cause, and how do you fix it?
Show answer
Git has no list of trusted SSH keys to check the signature against. Create an allowed signers file with your email and public key, and set gpg.ssh.allowedSignersFile to its path. Then run git tag -v v2.0.0 again.