Skip to content
$ lynuxpro
← Git

LESSON 12 OF 21 · INTERMEDIATE · 15 MIN

Tags and releases

HOW IT WORKSTags mark releases

points toa1b2c3dRelease readyv1.2.0annotated taggit push --tagsshare itCI pipelinebuild on tagReleaseimage 1.2.0
1/4

A tag is a permanent name for one commit. Unlike a branch, it never moves.

Branches move with every commit. Releases need the opposite: a name that never moves, so that "version 1.4.2" always means exactly the same code. Git tags provide that. This lesson covers lightweight and annotated tags, semantic versioning, sharing tags, and how CI/CD pipelines use tags to build and publish releases.

In simple words

  • Tag: a permanent name for one commit, usually a release version like v1.4.0.
  • Annotated tag: a tag with a message, author and date. The kind to use for releases.
  • Semantic versioning: MAJOR.MINOR.PATCH numbers: major for breaking changes, minor for new features, patch for fixes.

What a tag is

A tag is a permanent name for one commit. Like a branch it is a pointer, but it stays where you put it. Two kinds exist:

KindStoresUse for
Lightweightjust a pointer to a commitprivate bookmarks
Annotatedtagger, date, message (and optionally a signature)releases

Annotated tags are full objects in the repository, so they record who released what and when. git describe and many tools only consider annotated tags by default.

Look at existing tags

git config --global user.name "Leela Kumar"git clone https://gitlab.com/acme/shop.gitcd shopgit taggit log --oneline -n 6
SHELLbashutf-8 · 5L
v1.0.0ce797e5 (HEAD -> main, origin/main) Add CI pipelined2c0bba Report version in /healthc82322f Bump dependencies and tidy pricinga7b39ba Add Dockerfile2ff258c Add /total endpointe8b5455 (tag: v1.0.0) Document how to run the app
OUTPUTterminalutf-8 · 7L

v1.0.0 points at an older commit. You can check out exactly that release at any time with git switch --detach v1.0.0, or list what changed since it with git log --oneline v1.0.0..HEAD.

Create tags

git tag -a v1.1.0 -m "Release 1.1.0: /total endpoint, Dockerfile, CI"git tag local-testgit taggit show v1.1.0 --stat
SHELLbashutf-8 · 4L
local-testv1.0.0v1.1.0tag v1.1.0Tagger: Leela Kumar <learner@lynuxpro.dev>Release 1.1.0: /total endpoint, Dockerfile, CIcommit ce797e57d95fda935bce006ffcabeab2f0e5a9ff (HEAD -> main, tag: v1.1.0, tag: local-test, origin/main)Author: Leela Kumar <leela@acme.dev>Date:   Fri Nov 6 22:00:00 2026 +0000    Add CI pipeline .gitlab-ci.yml |   7 +++++++ 1 file changed, 7 insertions(+)
OUTPUTterminalutf-8 · 16L
  • git tag -a NAME -m "message" creates an annotated tag on the current commit.
  • git tag NAME creates a lightweight tag.
  • Tag an older commit by adding its hash: git tag -a v1.0.1 -m "Hotfix" c82322f.

Delete the test tag:

git tag -d local-test
SHELLbashutf-8 · 1L

Semantic versioning

Most projects name releases with semantic versioning (SemVer): MAJOR.MINOR.PATCH.

PartIncrease whenExample
MAJORyou make incompatible changes (breaking an API)1.4.2 → 2.0.0
MINORyou add functionality in a compatible way1.4.2 → 1.5.0
PATCHyou make compatible bug fixes1.4.2 → 1.4.3

Pre-releases add a suffix: 2.0.0-rc.1, 2.0.0-beta.3. Tags usually carry a v prefix (v1.4.2); pick one style and keep to it.

List tags matching a pattern, sorted as versions (so v1.10.0 comes after v1.9.0):

git tag -l "v1.*"
SHELLbashutf-8 · 1L
v1.0.0v1.1.0
OUTPUTterminalutf-8 · 2L

git describe: name any commit

git describe names a commit relative to the nearest annotated tag, which is perfect for build version strings:

printf 'Changelog\n' > CHANGELOG.mdgit add CHANGELOG.mdgit commit -m "Start changelog"git describe
SHELLbashutf-8 · 4L
[main 8d2c4a1] Start changelog 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.mdv1.1.0-1-g8d2c4a1
OUTPUTterminalutf-8 · 4L

Read it as: 1 commit after v1.1.0, at commit 8d2c4a1 (the g stands for git). Exactly on a tag, it prints just the tag name.

Sharing tags

git push does not push tags. Push them explicitly:

git push origin v1.1.0
SHELLbashutf-8 · 1L
To https://gitlab.com/acme/shop.git * [new tag]         v1.1.0 -> v1.1.0
OUTPUTterminalutf-8 · 2L

git push --tags pushes all local tags, including experiments you did not mean to share, so naming a tag is safer. To remove a tag that was pushed by mistake: git push origin --delete v1.1.0 (and git tag -d v1.1.0 locally).

Never move or reuse a released tag. If v1.1.0 was wrong, release v1.1.1. People and systems that already fetched v1.1.0 would otherwise have different code under the same name.

Tags in CI/CD

Pipelines commonly treat tags as release triggers. A GitLab CI example:

build-image:  stage: build  script:    - docker build -t registry.gitlab.com/acme/shop:$CI_COMMIT_TAG .    - docker push registry.gitlab.com/acme/shop:$CI_COMMIT_TAG  rules:    - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
OUTPUTterminalutf-8 · 7L

Pushing v1.1.0 builds and publishes image shop:v1.1.0 from exactly that commit. GitLab and GitHub also let you create a Release from a tag, with release notes and downloadable assets.

Generating release notes from history is one command:

git log --oneline v1.0.0..v1.1.0
SHELLbashutf-8 · 1L

Real-world scenario: "which version is in production?"

A team deployed straight from the latest main commit, and images were tagged latest. When a customer reported a bug, nobody could say which code was running. They switched to tagged releases: every production deploy is a SemVer tag, the image carries the same tag, and the app reports it on /health. "What is running?" now has a one-word answer, and git log v1.4.1..v1.4.2 shows exactly what changed between any two deployments.

Common mistakes

  • Expecting git push to send tags. Push them by name.
  • Using lightweight tags for releases; they lack author, date and message.
  • Moving or deleting a published release tag instead of releasing a new version.
  • Sorting versions as text, where v1.10.0 comes before v1.9.0. Use --sort=version:refname or tools that understand SemVer.
  • Image tag latest only, so deployments cannot be traced to code.

Practice

  1. Clone the shop project and list its tags.
  2. Create an annotated tag v1.1.0 with a message, and view it with git show.
  3. Add a commit and run git describe; explain each part of the output.
  4. Push the tag to origin.
  5. List all commits between v1.0.0 and v1.1.0.

Cheat sheet

git tag                                list tagsgit tag -l "v1.*" [--sort=version:refname]git tag -a v1.2.0 -m "msg" [commit]    annotated taggit tag name                           lightweight taggit show v1.2.0                        tag details and commitgit tag -d v1.2.0                      delete locallygit push origin v1.2.0                 share one taggit push --tags                        share all tagsgit push origin --delete v1.2.0        delete on the servergit describe [--tags]                  v1.2.0-3-g1a2b3c4git log --oneline v1.1.0..v1.2.0       release notes
OUTPUTterminalutf-8 · 11L

Key takeaways

  • Tags are fixed names for commits; use annotated tags for releases.
  • Name releases with semantic versioning: MAJOR.MINOR.PATCH.
  • Tags are not pushed automatically; push them by name.
  • Never move a published tag; release a new version instead.
  • CI/CD pipelines use tags to build, publish and trace releases.