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:
| Kind | Stores | Use for |
|---|---|---|
| Lightweight | just a pointer to a commit | private bookmarks |
| Annotated | tagger, 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 6v1.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 appv1.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 --statlocal-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(+)git tag -a NAME -m "message"creates an annotated tag on the current commit.git tag NAMEcreates 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-testSemantic versioning
Most projects name releases with semantic versioning (SemVer): MAJOR.MINOR.PATCH.
| Part | Increase when | Example |
|---|---|---|
| MAJOR | you make incompatible changes (breaking an API) | 1.4.2 → 2.0.0 |
| MINOR | you add functionality in a compatible way | 1.4.2 → 1.5.0 |
| PATCH | you make compatible bug fixes | 1.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.*"v1.0.0v1.1.0git 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[main 8d2c4a1] Start changelog 1 file changed, 1 insertion(+) create mode 100644 CHANGELOG.mdv1.1.0-1-g8d2c4a1Read 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.0To https://gitlab.com/acme/shop.git * [new tag] v1.1.0 -> v1.1.0git 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+$/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.0Real-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 pushto 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.0comes beforev1.9.0. Use--sort=version:refnameor tools that understand SemVer. - Image tag
latestonly, so deployments cannot be traced to code.
Practice
- Clone the shop project and list its tags.
- Create an annotated tag
v1.1.0with a message, and view it withgit show. - Add a commit and run
git describe; explain each part of the output. - Push the tag to
origin. - List all commits between
v1.0.0andv1.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 notesKey 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.