Skip to main content

What is a tag in Git?

A tag in Git is a named marker on a specific commit, usually used to denote a version or a release.

In simpler terms: a tag is a "label" on a commit with a readable name like v1.2.0.


Why tags are needed

Tags let you:

  • mark releases and versions
  • easily go back to a needed state of the code
  • trigger CI/CD based on a version
  • have a stable point in history (unlike branches)

A branch "moves", a tag does not.


What this looks like in practice

Commit history:

A---B---C---D---E v1.0.0

The v1.0.0 tag points exactly at commit C and will always point at it.


Main types of tags

1. Lightweight tag

  • just a reference to a commit
  • no description or metadata
bash
git tag v1.0.0

Rarely used, mostly for local markers.


  • contains the author
  • the date
  • a message
  • stored as a separate object in Git
bash
git tag -a v1.0.0 -m "Release version 1.0.0"

These are the tags used for releases.


Tags and releases (important point)

  • A tag is a Git object
  • A release is an entity of the platform (GitHub / GitLab)

Usually:

  1. a v1.2.0 tag is created
  2. based on it, a release with a changelog is created

How tags work with a remote repository

By default, tags are not pushed automatically.

bash
git push origin v1.0.0

Or all at once:

bash
git push --tags

Tags in CI/CD

Very often:

  • a pipeline is triggered by a tag
  • deployment to production happens only from tags
  • the tag name equals the application's version

Example:

text
v1.3.2 → deploy to production

What is important to emphasize in an interview

  • a tag is not a branch
  • a tag does not move
  • a tag points to a specific commit
  • annotated tags are used for releases

Short answer for an interview

A tag in Git is a named marker on a specific commit, usually used to denote a version or a release. Unlike a branch, a tag does not change and always points to the same state of the code.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

What is a tag in Git?: Git Interview Question