Tags and releases

Intermediate · 11 min

Mark a commit as version 1.0 with a tag. Lightweight versus annotated tags, why git push doesn't send them, and what to do about a tag you got wrong.

Before thisFetch, pull and pushHow Git stores history

GitKraken · 11 min

Tags and releases

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

Taught by GitKrakenReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A tag is a permanent name for one commit, used to mark releases such as `v1.0.0`, unlike a branch, which moves with each new commit.
  • A lightweight tag is just a ref to a commit, while an annotated tag (`git tag -a`) is its own object with a tagger, date and message.
  • `git push` does not send tags: push one with `git push origin <tag>`, or push annotated tags reachable from your commits with `git push --follow-tags`.
  • A published tag should never be moved, and Git refuses to overwrite one that already exists on the remote.
  • `git describe` names any commit relative to the nearest annotated tag, such as `v0.2.0-1-g70a4eb4`.

Why branches can’t mark a release

You ship jot to a few friends and, a month later, one of them reports a bug in “the version I installed”. Which commit was that? A branch can’t answer, because main has moved on forty commits since. You need a name that stays glued to one commit forever.

That is a tag. Underneath it is the same thing as a branch: a file under .git/refs/ holding a commit hash. The difference is behaviour. Committing moves the current branch forward. Nothing moves a tag.

Two kinds

$ git tag v0.1.0
$ git tag -a v0.2.0 -m "Release 0.2.0: add and list"
$ git tag
v0.1.0
v0.2.0
$ git tag -n
v0.1.0          Expand README
v0.2.0          Release 0.2.0: add and list

v0.1.0 is lightweight: just a ref. Its -n annotation shows the commit’s own subject. v0.2.0 is annotated: Git created a separate object holding the tagger, a date and your message.

$ git cat-file -t v0.1.0
commit
$ git cat-file -t v0.2.0
tag
$ git show -s v0.2.0
tag v0.2.0
Tagger: Ada Example <ada@example.com>
Date:   Mon Nov 23 01:50:38 2026 +0530

Release 0.2.0: add and list

commit c1a3b1dd6ecd...

For releases, use annotated tags. They record who tagged and when, they can be signed, and tools such as git describe prefer them. Lightweight tags suit private bookmarks.

Tags are not pushed by default

This is the usual surprise. A plain git push sends branches only:

$ git push
Everything up-to-date
$ git ls-remote --tags origin
$

Nothing on the remote. Push a tag by name, or let Git push the annotated tags that point into the history you’re pushing:

$ git push origin v0.2.0
To ../hub.git
 * [new tag]         v0.2.0 -> v0.2.0
$ git tag -a v0.3.0 -m "Release 0.3.0"
$ git push --follow-tags
To ../hub.git
   c1a3b1d..70a4eb4  main -> main
 * [new tag]         v0.3.0 -> v0.3.0

--follow-tags skips lightweight tags, which is a feature: you don’t accidentally publish a private bookmark. git push --tags pushes every tag, including those. In the ls-remote output, an annotated tag shows twice, once for the tag object and once, with ^{}, for the commit it points to.

A teammate gets tags with an ordinary git fetch, which downloads tags that point into histories it fetches. git fetch --tags fetches all of them.

Naming a commit from a tag

After tagging v0.2.0 I made one more commit:

$ git describe
v0.2.0-1-g70a4eb4

Read it as “one commit after v0.2.0, at commit 70a4eb4” (the g stands for git). Build scripts use this to stamp a version into a binary. Plain git describe only considers annotated tags. Add --tags to include lightweight ones.

Mistakes and moving tags

Delete a local tag with git tag -d <name> and a remote one with git push origin --delete <name>. Retagging is the trap. I moved a tag locally with git tag -f and tried to push it after it already existed on the remote:

$ git tag -f v0.1.0 HEAD~1
Updated tag 'v0.1.0' (was 70a4eb4)
$ git push origin v0.1.0
 ! [rejected]        v0.1.0 -> v0.1.0 (already exists)
hint: Updates were rejected because the tag already exists in the remote.

Git protects published tags. You could force it, but that leaves everyone who already fetched the old tag with the wrong commit and no warning. The fix is social: leave the old tag alone and release v0.1.1.

Sort tags by version, not alphabetically, with git tag --sort=-v:refname. Alphabetical order puts v0.10.0 before v0.2.0.

Tags and hosted releases

Hosting services build a “release” page on top of a tag: a title, notes and downloadable files. The release is the platform’s feature, and the tag is Git’s. I could not use a hosting service while writing this lesson, so the release page itself is not shown. The Git half above is what a release is built on. Version numbers and what they mean come in conventional commits and semantic versioning.

What the video covers

GitKraken’s “Git Tutorial #40: How to Create, Checkout, and Delete Git Tags” is about eleven minutes and was published around 2022. From its title it covers creating, checking out and deleting tags, which is the first half of this lesson. GitKraken makes a Git client, so it may show the GUI next to the command line. I judge English from the title, description and channel only, and I could not read a transcript. I can’t say whether it covers pushing tags, so the push section, --follow-tags and the moved-tag failure are from my own runs. Two shorter videos from smaller channels are linked as alternatives.

Where this fits

A tag is a name on a commit. The next lesson uses several remotes at once: forks and multiple remotes.

Check yourself

  1. 01How is a tag different from a branch?

    A branch ref moves forward when you commit. A tag ref stays on the commit you tagged, so it is a stable name for a release.

  2. 02What does an annotated tag store that a lightweight tag doesn't?

    A separate tag object with the tagger's name and email, a date and a message, and it can also be signed.

  3. 03You ran `git push` and a teammate can't see your `v1.0.0` tag. Why?

    Tags are not pushed by default. Push it with `git push origin v1.0.0`, or use `git push --follow-tags` for annotated tags.

  4. 04You tagged the wrong commit and already pushed the tag. What should you do?

    Create a new tag, such as `v1.0.1`, on the right commit. Moving a published tag leaves other clones with the old one, and Git refuses to overwrite it on the remote anyway.

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