Git Tag Explained (Create, Push, Delete & Best Practices)

Git Tag Explained (Create, Push, Delete & Best Practices)

What is Git Tag?

Git tag is used to mark a specific point in your Git history, usually to represent a version, release, or important milestone in your project.

For example, when you release version v1.0 of your application, you can create a tag:

bash
git tag v1.0

This acts like a permanent reference to that exact state of your code.

In simple terms:

Git tag = label for a specific commit (used for versions/releases)

Why do we use Git tags?

Git tags are mainly used to:

  • Mark release versions (e.g., v1.0, v2.0)
  • Track important milestones in development
  • Easily reference stable versions of code
  • Simplify deployments and CI/CD workflows

Instead of remembering commit hashes, you can use readable names like v1.0.

Tags are widely used in workflows explained in git workflow, especially for release management.

What does git tag do?

When you create a tag:

  • It points to a specific commit
  • It does not change automatically (unlike branches)
  • It helps you revisit that exact version anytime

Tags are static references, while branches move forward with new commits.

What is tagging in Git?

Tagging in Git means assigning a name (tag) to a specific commit.

There are two types of tags:

  • Lightweight tag → simple reference
  • Annotated tag → includes metadata (author, message, date)

Annotated tags are recommended for releases because they provide more context.


Git Tag – Quick Cheat Sheet

DescriptionCommand
Create lightweight taggit tag <tag>
Create annotated taggit tag -a <tag> -m "message"
Create tag for specific commitgit tag <tag> <commit>
Create version taggit tag v1.0.0
List all tagsgit tag
List tags with patterngit tag -l "v1.*"
Show tag detailsgit show <tag>
Show tag commitgit show <tag>
Push single taggit push origin <tag>
Push all tagsgit push origin --tags
Fetch tags from remotegit fetch --tags
Delete local taggit tag -d <tag>
Delete remote taggit push origin --delete <tag>
Update/move tagdelete + recreate
Force update taggit tag -f <tag>
Checkout taggit checkout tags/<tag>
Create branch from taggit checkout -b <branch> <tag>
Tag current HEADgit tag <tag>
Tag previous commitgit tag <tag> HEAD~1
Verify tag (GPG)git tag -v <tag>
Create signed taggit tag -s <tag>
Rename tagdelete + recreate
Sort tagsgit tag --sort=version:refname
List latest taggit describe --tags
Push specific tag with forcegit push -f origin <tag>
Delete all local tagsgit tag -l | xargs git tag -d
Check tag historygit log --tags
Tag after commitgit tag <tag>
Add tag to commitgit tag <tag> <commit>

Quick Examples

bash
# Create annotated tag
git tag -a v1.0 -m "First release"

# Push tag
git push origin v1.0

# List tags
git tag

# Checkout tag
git checkout tags/v1.0

# Delete tag
git tag -d v1.0

Create Git Tag

Create lightweight tag

A lightweight tag is the simplest way to mark a commit in Git. It acts as a pointer to the current commit without storing additional metadata.

bash
git tag v1.0

This is useful for quickly marking versions or milestones during development.

Before creating tags, ensure your repository is properly initialized using git init tutorial.

Create annotated tag

Annotated tags are recommended for releases because they include metadata such as author, date, and message.

bash
git tag -a v1.0 -m "First stable release"

These tags provide better context and are commonly used in production workflows. Writing meaningful messages here follows the same best practices as git commit message.

Create tag for specific commit

You can create a tag for any past commit using its hash:

bash
git tag v1.1 <commit-hash>

To find the commit hash, you can use:

bash
git log --oneline

Understanding commit references like HEAD~1 or hashes is explained in git head caret vs tilde examples.


List and View Tags

List all tags in Git

To view all tags in your repository:

bash
git tag

This lists all tags, helping you track versions and milestones.

Filter tags by pattern

You can filter tags using patterns:

bash
git tag -l "v1.*"

This is useful when working with version-based tagging (e.g., semantic versioning like v1.0, v1.1).

Show tag details

To view detailed information about a tag:

bash
git show v1.0

This displays:

  • commit message
  • author
  • changes introduced

This is similar to inspecting commits using git show command, but focused on tagged versions.


Push and Share Tags

Push single tag to remote

After creating a tag locally, you need to push it to the remote repository:

bash
git push origin v1.0

This shares the tag with your team so everyone can access the same version.

For general push behavior, refer to git push examples.

Push all tags

To push all local tags at once:

bash
git push origin --tags

This is useful when you have created multiple tags and want to sync them with the remote repository.

Fetch tags from remote

To download tags from the remote repository:

bash
git fetch --tags

This ensures your local repository is updated with all tags created by others. Learn more about fetching in git fetch examples.


Manage Tags (Update, Delete, Move)

Delete local and remote tag

To delete a local tag:

bash
git tag -d v1.0

To delete a remote tag:

bash
git push origin --delete v1.0

This helps keep your repository clean by removing outdated or incorrect tags.

Move or update tag

Git tags are meant to be immutable, but you can update them if needed.

To move a tag:

bash
git tag -f v1.0 <commit-hash>

Then push the updated tag:

bash
git push -f origin v1.0
WARNING
Use this carefully, as it rewrites history and can affect collaborators.

Rename tag

Git does not support renaming directly. Instead:

bash
git tag -d old-tag
git tag new-tag

Then push changes:

bash
git push origin --delete old-tag
git push origin new-tag

This approach ensures consistency across local and remote repositories.


Checkout and Use Tags

Checkout tag in Git

To view code at a specific tag:

bash
git checkout tags/v1.0

This puts your repository into a detached HEAD state.

Learn more about this state in git detached head examples.

Create branch from tag

To start development from a tagged version:

bash
git checkout -b feature-v1 v1.0

This is useful when you want to fix bugs or build features based on a stable release. Branch workflows are explained in git branch examples.

Difference between tag vs branch

  • Tag → fixed reference to a specific commit
  • Branch → moving pointer that updates with new commits

Use tags for:

  • releases
  • versioning

Use branches for:

  • feature development
  • ongoing work

To understand this better, refer to git merge vs rebase for how branches evolve over time.


Fix Common Errors

tag already exists

This error occurs when you try to create a tag with a name that already exists:

bash
fatal: tag 'v1.0' already exists

Fix options:

  • Use a different tag name
  • Delete the existing tag and recreate it
bash
git tag -d v1.0
git tag v1.0

If the tag exists on remote, delete it there as well before recreating.

tag not pushed

By default, tags are not pushed automatically when you push commits.

Fix:

Push a specific tag:

bash
git push origin v1.0

Or push all tags:

bash
git push origin --tags

This is a common confusion since normal git push only pushes branches. Learn more about push behavior in git push examples.

cannot checkout tag

This error can happen due to:

  • Incorrect tag name
  • Tag not fetched from remote
  • Detached HEAD confusion

Fix:

bash
git fetch --tags
git checkout tags/v1.0

When you checkout a tag, Git enters a detached HEAD state. To continue development, create a branch:

bash
git checkout -b new-branch v1.0

Learn more about this behavior in git detached head examples.


Frequently Asked Questions

1. What is git tag?

Git tag is used to mark a specific commit in Git history, usually to represent a version or release of a project.

2. How do I create a tag in Git?

You can create a tag using git tag <tag> for a lightweight tag or git tag -a <tag> -m "message" for an annotated tag.

3. How do I push tags to remote?

You can push a tag using git push origin <tag> or push all tags using git push origin --tags.

4. How do I delete a Git tag?

You can delete a local tag using git tag -d <tag> and a remote tag using git push origin --delete <tag>.

5. What is the difference between tag and branch in Git?

A tag is a fixed reference to a commit, while a branch is a moving pointer that updates with new commits.

Summary

Git tags are essential for marking versions and important milestones in your project.

In this guide, you learned how to:

  • Create lightweight and annotated tags
  • List and inspect tags
  • Push and share tags with remote repositories
  • Manage tags (delete, update, move)
  • Use tags for versioning and releases
  • Fix common tagging errors

Using Git tags effectively helps maintain clear version history, improves collaboration, and simplifies release management.


Official Documentation

Steve Alila

Steve Alila

Specializes in web design, WordPress development, and data analysis, with proficiency in Python, JavaScript, and data extraction tools. Additionally, he excels in web API development, AI integration, and data presentation using Matplotlib and Plotly.