Lesson 26 of 60 – Git Tags
43%

Git Tags

A Git tag is a reference that points to a specific commit in a Git repository. Tags are commonly used to mark important points in project history, such as software releases, versions, and milestones.

Note: Tags are useful when you want to give a meaningful name to a particular commit, such as v1.0.0, v2.0.0, or release-2026.

1. What is a Git Tag?

A Git tag is a named reference to a specific commit.

v1.0.0 → Commit A

Instead of remembering a long commit hash, you can use a meaningful tag name to identify an important version.

2. Why Use Git Tags?

Tags are commonly used to mark important versions or milestones.

  • Mark software releases
  • Identify stable versions
  • Mark project milestones
  • Identify production releases
  • Make important commits easier to find

3. Example of a Version Tag

Suppose a project reaches its first stable release:

v1.0.0

You can create a tag named v1.0.0 pointing to the corresponding commit.

git tag v1.0.0

4. Creating a Lightweight Tag

A simple tag can be created with:

git tag v1.0.0

This creates a lightweight tag that points directly to the current commit.

5. Listing Tags

Use the following command to list tags:

git tag

Example:

v1.0.0
v1.1.0
v2.0.0

6. Creating an Annotated Tag

An annotated tag stores additional information such as the tagger, date, message, and tag object.

git tag -a v1.0.0 -m "First stable release"

Annotated tags are commonly useful for release points.

7. Lightweight vs Annotated Tags

Lightweight Tag Annotated Tag
Simple reference Full tag object
Points directly to a commit Stores tag information
git tag v1.0.0 git tag -a v1.0.0 -m "Release"

8. Tagging a Specific Commit

You can create a tag for a specific commit instead of the current commit.

git tag v1.0.0 8f32abc

Here, 8f32abc represents the commit that should receive the tag.

9. Annotated Tag on a Specific Commit

You can also create an annotated tag on a specific commit:

git tag -a v1.0.0 8f32abc -m "First stable release"

10. Viewing Tag Information

Use git show to inspect a tag:

git show v1.0.0

For an annotated tag, Git can show the tag information and the associated commit details.

11. Viewing Tags with a Pattern

You can filter tags using a pattern:

git tag -l "v1.*"

This can display tags that begin with v1..

12. Semantic Version Tags

Many software projects use version formats such as:

v1.0.0
v1.1.0
v1.2.0
v2.0.0

This style is commonly associated with semantic versioning.

13. Tagging a Release

After completing a stable version of an application, you can create a release tag:

git tag -a v1.0.0 -m "Release version 1.0.0"

The tag provides a convenient reference to that release point.

14. Pushing a Tag to a Remote

Tags are not automatically pushed to a remote repository by a normal git push in the same way as ordinary branch updates. You can explicitly push a tag:

git push origin v1.0.0

15. Pushing All Tags

To push all local tags to a remote:

git push origin --tags

This sends local tags that are not already present on the remote.

16. Deleting a Local Tag

To delete a tag from your local repository:

git tag -d v1.0.0

This removes the local tag reference.

17. Deleting a Remote Tag

To delete a tag from a remote repository:

git push origin --delete v1.0.0

This removes the specified tag from the remote repository.

18. Checking Out a Tag

You can inspect the project at a tagged commit:

git switch --detach v1.0.0

This checks out the tagged commit in a detached HEAD state.

19. Detached HEAD with a Tag

When you switch directly to a tag, HEAD is normally detached from a branch.

HEAD → v1.0.0 → Commit

You can inspect or test that version without moving a branch pointer.

20. Creating a Branch from a Tag

If you want to continue development from a tagged version, create a new branch:

git switch -c maintenance-v1 v1.0.0

This creates a new branch starting at the commit referenced by the tag.

21. Finding Tags for a Commit

You can inspect which tags point to a particular commit using:

git tag --points-at 8f32abc

This is useful when you want to identify tags associated with a specific commit.

22. Tags and GitHub

When tags are pushed to GitHub, they can be used to identify specific versions of a project and can also be associated with GitHub releases.

git push origin v1.0.0

The tag remains a Git reference pointing to a specific commit.

23. Tagging After a Commit

git add .
git commit -m "Complete payment module"

git tag -a v2.0.0 -m "Payment module release"

The tag is created at the current commit.

24. Listing Tags with Messages

You can list tags along with their messages:

git tag -n

Example:

v1.0.0  First stable release
v1.1.0  Add user dashboard
v2.0.0  Major application update

25. Sorting Version Tags

Git can sort tags using version-aware sorting:

git tag --sort=version:refname

This can be useful when a project has many version tags.

26. Common Git Tag Mistakes

  • Creating a tag on the wrong commit.
  • Forgetting to push the tag to the remote repository.
  • Using unclear tag names.
  • Deleting a tag without checking where it is used.
  • Confusing tags with branches.
  • Making changes directly while in detached HEAD without creating a branch.
  • Using the same tag name for unrelated releases.

27. Useful Git Tag Commands

git tag
git tag v1.0.0
git tag -a v1.0.0 -m "Release 1.0.0"
git tag -l "v1.*"
git tag -n
git show v1.0.0
git tag -d v1.0.0
git push origin v1.0.0
git push origin --tags
git push origin --delete v1.0.0

28. Complete Release Tag Workflow

# Check status
git status

# View recent commits
git log --oneline

# Create annotated tag
git tag -a v1.0.0 -m "First stable release"

# View the tag
git show v1.0.0

# Push the tag
git push origin v1.0.0

# Verify local tags
git tag

29. Practical Example

git init

git add .
git commit -m "Initial project"

git tag -a v1.0.0 -m "Initial stable release"

git tag

git show v1.0.0

git push origin v1.0.0

The project now has a named release point that refers to the commit containing the initial stable version.

30. Summary of Git Tags

Git tags provide meaningful names for important commits. They are commonly used for software releases and project milestones.

git tag v1.0.0

git tag -a v1.0.0 -m "Release 1.0.0"

Tags can be listed, inspected, pushed to remote repositories, deleted, and used to inspect a specific version of a project.

📌 Key Points

  • A Git tag is a named reference to a specific commit.
  • Tags are commonly used for releases and milestones.
  • git tag v1.0.0 creates a lightweight tag.
  • git tag -a creates an annotated tag.
  • git tag lists local tags.
  • git show v1.0.0 displays information about a tag.
  • git tag -d deletes a local tag.
  • git push origin v1.0.0 pushes a specific tag.
  • git push origin --tags pushes local tags to the remote.
  • git push origin --delete deletes a remote tag.
  • Checking out a tag normally results in a detached HEAD state.
  • A branch can be created from a tag when further development is needed.

🧠 Quick Quiz

Question: What is a Git tag mainly used for?