Using Git Tags – Version Control for Releases & Milestones

Why Use Git Tags?

Git tags allow developers to mark specific points in a repository’s history, making it easy to reference important commits, such as release versions, stable milestones, or critical changes.

Track software versions – Easily refer to specific releases like v1.0.0.
Mark key points in history – Identify commits for deployment, debugging, or rollbacks.
Organize project milestones – Create structured releases in a version-controlled way.
Automate CI/CD Pipelines – Use tags to trigger deployments or build processes automatically.
Tag important commits for collaboration – Help teams navigate large repositories efficiently.

This guide covers creating, managing, and working with Git tags effectively.


Types of Git Tags

There are two main types of tags in Git:

1️⃣ Lightweight Tags

A simple pointer to a specific commit (similar to a branch but won’t move).

git tag v1.0.0

2️⃣ Annotated Tags

Stores extra metadata (author, date, message) and is recommended for public releases.

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

️ Creating & Managing Git Tags

Creating a Tag on a Specific Commit

If you want to tag an older commit, find its commit hash:

git log --oneline

Then tag it:

git tag v1.0.0 <commit-hash>

Listing All Tags

git tag

Viewing Tag Details

For annotated tags, see more details:

git show v1.0.0

Deleting a Local Tag

git tag -d v1.0.0

Deleting a Remote Tag

git push origin --delete v1.0.0

Pushing & Fetching Tags in Remote Repositories

By default, tags are not pushed to remote repositories. Push a tag manually:

git push origin v1.0.0

To push all tags:

git push --tags

Fetch remote tags:

git fetch --tags

⏪ Checking Out a Tagged Version

To view the code as it was at a specific tag:

git checkout v1.0.0

This puts your repo in a detached HEAD state, meaning changes won’t be saved to a branch. To create a new branch from a tag:

git checkout -b bugfix-v1.0.0 v1.0.0

Using Tags in CI/CD Pipelines

Many CI/CD systems, including GitHub Actions, GitLab CI/CD, and Jenkins, support tags to trigger specific workflows automatically.

  • Trigger a build when a new tag is pushed:
on:
  push:
    tags:
      - 'v*'  # Triggers the pipeline for any tag starting with 'v'
  • Deploy production releases based on tags – Automate versioned deployments by tagging releases.
  • Tag important releases for rollback – Quickly switch between production versions.

Best Practices for Using Git Tags

Use annotated tags for official releases – They store extra metadata and are more informative.
Follow versioning conventions – Use semantic versioning (v1.2.3, v2.0.0-beta).
Push tags to remote repositories – Ensure consistency between local and remote repositories.
Use tags to track deployments – Easily roll back to previous releases if needed.
Integrate tags with CI/CD workflows – Automate builds and deployments efficiently.


Next Steps

Now that you know how to use Git tags, explore more Git topics:

Git Best Practices – Keep your repository structured and clean.
Working with .gitignore – Learn how to ignore unnecessary files.
Using Git in Large Projects – Manage large repositories with best practices.

Need help? Check the official Git documentation or ask in the comments!