Git Tags & Releases: Complete Guide with Examples
84 people viewed this
Git Tags & Releases: Complete Guide with Examples
When working on a software project, you often reach important milestones such as v1.0.0, v1.1.0, or v2.0.0.
But how do you mark these specific versions in Git so that you can easily find them later?
This is where Git tags come in.
A Git tag is a reference to a specific commit in your repository. Tags are commonly used to mark important versions such as production releases.
In this article, we will learn Git tags and releases from the basics to practical workflows used by developers.
What Is a Git Tag?
A Git tag is a named reference that points to a specific commit.
Instead of remembering a commit hash such as:
8f3a9c7d2b...
you can give that commit a meaningful name:
v1.0.0
For example:
git tag v1.0.0
Now v1.0.0 identifies a particular point in your Git history.
Why Are Git Tags Used?
Tags are especially useful for identifying important versions of an application.
- Mark production releases
- Identify stable versions
- Mark milestones
- Reference a specific deployment
- Rollback to a known version
- Connect source code with release versions
- Make version history easier to understand
For example, a Laravel application might have:
v1.0.0
v1.1.0
v1.2.0
v2.0.0
Types of Git Tags
Git mainly provides two commonly used types of tags:
- Lightweight tags
- Annotated tags
1. What Is a Lightweight Tag?
A lightweight tag is simply a name that points to a commit.
Example:
git tag v1.0.0
This creates a lightweight tag named v1.0.0.
Lightweight tags are useful when you simply need a temporary or simple reference to a commit.
2. What Is an Annotated Tag?
An annotated tag stores additional information such as:
- Tag name
- Tag message
- Tagger information
- Date
- Reference to the tagged commit
Create an annotated tag using:
git tag -a v1.0.0 -m "Release version 1.0.0"
For official software releases, annotated tags are commonly preferred because they contain metadata describing the release.
Lightweight Tag vs Annotated Tag
| Lightweight Tag | Annotated Tag |
|---|---|
| Simple reference to a commit | Contains tag metadata |
| No tag message | Can contain a message |
| Simple to create | Better suited for formal releases |
git tag v1.0.0 |
git tag -a v1.0.0 -m "Release" |
How to Create a Git Tag
First, check your current branch:
git branch
Check the latest commits:
git log --oneline
Then create an annotated tag:
git tag -a v1.0.0 -m "Release version 1.0.0"
The tag is now created locally.
How to Tag an Older Commit
You do not have to tag only the latest commit.
First find the commit:
git log --oneline
Suppose the commit is:
abc1234 Fix payment calculation
You can create a tag on that commit:
git tag -a v1.0.0 abc1234 -m "Release version 1.0.0"
How to List Git Tags
To display all tags:
git tag
Example output:
v1.0.0
v1.1.0
v1.2.0
v2.0.0
You can also search tags using a pattern:
git tag -l "v1.*"
How to See Information About a Tag
Use:
git show v1.0.0
For an annotated tag, this can show the tag information and the referenced commit.
How to Push a Git Tag to Remote
Creating a tag locally does not automatically publish it to your remote repository.
Push a specific tag:
git push origin v1.0.0
To push all local tags:
git push origin --tags
After pushing, the tag becomes available in the remote repository.
How to Fetch Tags from a Remote Repository
If another developer has created tags on the remote repository, you can fetch them using:
git fetch --tags
Then:
git tag
You can see the available tags locally.
How to Delete a Local Git Tag
To delete a tag from your local repository:
git tag -d v1.0.0
This removes the local tag reference.
How to Delete a Remote Git Tag
To delete the tag from the remote repository:
git push origin --delete v1.0.0
An alternative syntax is:
git push origin :refs/tags/v1.0.0
How to Checkout a Git Tag
You can inspect the code exactly as it existed at a particular tag.
git checkout v1.0.0
However, this normally puts you in a detached HEAD state.
If you want to start new work from that version, create a branch:
git switch -c bugfix-from-v1 v1.0.0
This creates a new branch starting from the tagged commit.
What Is Semantic Versioning?
Git itself does not require a specific version naming system, but many projects use Semantic Versioning, commonly written as SemVer.
A typical version looks like:
MAJOR.MINOR.PATCH
Example:
2.4.1
- 2 = Major version
- 4 = Minor version
- 1 = Patch version
What Does a Major Version Mean?
A major version is generally used when introducing incompatible changes that may require users to modify their code or configuration.
Example:
1.9.5 → 2.0.0
What Does a Minor Version Mean?
A minor version is commonly used for adding new functionality while maintaining compatibility with the existing major version.
Example:
1.4.2 → 1.5.0
What Does a Patch Version Mean?
A patch version is commonly used for backward-compatible bug fixes.
Example:
1.5.0 → 1.5.1
What Is a Git Release?
A release represents a version of your software that is packaged and published for users or deployment.
A release is usually associated with a Git tag.
For example:
Tag:
v1.2.0
Release:
Version 1.2.0
Release Notes:
- Added invoice export
- Improved search
- Fixed payment issue
The exact release functionality depends on the hosting platform, such as GitHub or GitLab. Git itself provides tags; a platform can provide a richer release page around a tag.
Git Tag vs Release
| Git Tag | Release |
|---|---|
| Points to a specific commit | Represents a published software version |
| Created using Git | Usually managed through a hosting platform |
| Can identify source code | Can include release notes and downloadable assets |
| Exists in Git history | Provides a user-facing release representation |
Typical Git Tag and Release Workflow
A common release workflow looks like this:
1. Develop features
↓
2. Test the application
↓
3. Merge changes
↓
4. Prepare production version
↓
5. Create Git tag
↓
6. Push tag
↓
7. Create release
↓
8. Deploy version
Practical Example: Laravel Project Release
Suppose you are maintaining a Laravel application and have completed a new version.
First check your working tree:
git status
Make sure your changes are committed:
git add .
git commit -m "Prepare version 1.5.0"
Create an annotated tag:
git tag -a v1.5.0 -m "Release version 1.5.0"
Verify it:
git show v1.5.0
Push the tag:
git push origin v1.5.0
Your remote repository can now use v1.5.0 as the reference for this version.
What Should Release Notes Contain?
Good release notes help developers and users understand what changed between versions.
A release might contain sections such as:
Added
- Added invoice export
- Added user notification system
Changed
- Updated dashboard UI
- Improved database queries
Fixed
- Fixed payment calculation issue
- Fixed incorrect invoice totals
Can You Move a Git Tag?
Yes, a tag can technically be moved, but moving a published release tag should be avoided unless there is a clear reason and the team understands the consequences.
For example, deleting and recreating a tag:
git tag -d v1.0.0
git tag -a v1.0.0 -m "Updated release"
If the old tag has already been pushed, changing it on the remote also requires a force update.
git push origin --force v1.0.0
Because a published tag is commonly used as an immutable reference to a release, changing it can cause confusion for other developers and deployment systems.
How to Tag the Current Commit
To create a lightweight tag on the current commit:
git tag v1.0.0
To create an annotated tag:
git tag -a v1.0.0 -m "Release version 1.0.0"
How to Find Which Commit a Tag Points To
Use:
git rev-list -n 1 v1.0.0
You can also inspect the tag with:
git show v1.0.0
Important Git Tag Commands
| Command | Purpose |
|---|---|
git tag |
List tags |
git tag v1.0.0 |
Create lightweight tag |
git tag -a v1.0.0 -m "Release" |
Create annotated tag |
git show v1.0.0 |
Show tag information |
git push origin v1.0.0 |
Push one tag |
git push origin --tags |
Push all tags |
git fetch --tags |
Fetch tags from remote |
git tag -d v1.0.0 |
Delete local tag |
git push origin --delete v1.0.0 |
Delete remote tag |
git checkout v1.0.0 |
Checkout tagged version |
Git Tag Best Practices
- Use a consistent naming convention. For example, use
v1.0.0,v1.1.0, andv2.0.0. - Use annotated tags for official releases.
- Do not casually move published release tags.
- Write meaningful release messages.
- Tag a tested commit.
- Keep release versions consistent with your deployment process.
Git Tags & Releases Interview Questions
- What is a Git tag?
- Why are Git tags used?
- What is the difference between a tag and a branch?
- What is a lightweight tag?
- What is an annotated tag?
- What is the difference between lightweight and annotated tags?
- How do you create a Git tag?
- How do you create an annotated tag?
- How do you tag an older commit?
- How do you list all Git tags?
- How do you push a tag to a remote repository?
- How do you push all tags?
- How do you delete a local tag?
- How do you delete a remote tag?
- How do you checkout a tagged version?
- What is Semantic Versioning?
- What is the difference between a Git tag and a release?
- Can a Git tag be moved?
- Why should published release tags generally be treated as stable references?
- How would you create and publish a production release?
Interview Scenario: How Would You Release Version 2.0.0?
An interviewer may ask you to explain the complete process.
A practical answer could be:
# Check current status
git status
# Review commits
git log --oneline
# Create the release commit
git add .
git commit -m "Prepare version 2.0.0"
# Create annotated tag
git tag -a v2.0.0 -m "Release version 2.0.0"
# Verify tag
git show v2.0.0
# Push code
git push origin main
# Push tag
git push origin v2.0.0
After the tag is pushed, the repository hosting platform can use that tag as the basis for a release containing release notes and, depending on the platform, downloadable assets.
How Git Tags Can Help With Deployment
Tags are useful in deployment workflows because they provide a specific version that can be deployed.
For example:
v1.4.0 → Production
v1.5.0 → Production
v1.6.0 → Production
Instead of saying "deploy whatever is currently on the main branch", a deployment process can be designed around a specific release tag.
This can make it easier to identify exactly which source version was deployed.
Conclusion
Git tags provide a simple way to mark important commits in your repository. They are especially useful for identifying application versions such as v1.0.0, v1.1.0, and v2.0.0.
For formal releases, annotated tags are commonly used because they include useful metadata and a release message.
A release is a broader, user-facing representation of a software version, often built around a Git tag by a hosting platform.
Understanding tags and releases is important for developers working with production deployments, CI/CD pipelines, version management, and collaborative Git workflows.
Quick Revision
# Create lightweight tag
git tag v1.0.0
# Create annotated tag
git tag -a v1.0.0 -m "Release version 1.0.0"
# List tags
git tag
# Show tag
git show v1.0.0
# Push tag
git push origin v1.0.0
# Push all tags
git push origin --tags
# Fetch tags
git fetch --tags
# Delete local tag
git tag -d v1.0.0
# Delete remote tag
git push origin --delete v1.0.0
Was this useful?
No ratings yet — yours can be the first.
Discussion
Notes from readers. Comments appear after a short review.
No comments yet. Start the thread below.