Release Tags: Which Build Should You Tag?
In this article
This article explains which build you should tag as a release in a software project, covering the key factors like stability, versioning, and branch strategy. You'll learn the practical rules for choosing the right commit, how to handle hotfixes, and common mistakes to avoid. The answer is: tag the commit that represents the final, tested, and deployable state of the code for that release, typically on a release branch or the main branch after all acceptance criteria are met.
What a Release Tag Actually Is
A release tag is a named pointer to a specific commit in your version control history, usually following a version number like v1.2.3 or release/2.0. Unlike a branch, which moves forward as you add commits, a tag is immutable—it marks a fixed point in time. This lets you reproduce the exact code that was shipped, roll back if needed, and communicate clearly to your team and users what version they are running.
Tags are not the same as releases on platforms like GitHub or GitLab, though they are often linked. A tag is the underlying Git object; a release is a higher-level feature that attaches release notes, binaries, and a changelog to that tag. For the purpose of this article, we focus on the Git tag itself—the commit you choose to label.
Why the Choice Matters
Choosing the wrong commit to tag has real consequences. If you tag a commit that is missing a last-minute fix, users get a broken release. If you tag a commit that includes untested features, you may introduce regressions. If you tag before merging a critical security patch, you leave a known vulnerability in the wild. The tag is the contract between your team and your users: it says, "This exact code is what we stand behind."
In continuous delivery environments, the tag often triggers automated deployment to production. That means the tagged commit should be identical to what was actually deployed and verified, not just a close approximation. A common mistake is tagging a merge commit that hasn't passed the full test suite, or tagging a commit on a feature branch that was never merged into the main line.
How to Choose the Right Commit
Here is a practical decision process for selecting the commit to tag:
- Use the release branch: If you follow Git Flow, tag on the
release/branch after all fixes for that version are merged and tested. This branch exists specifically for stabilizing a release. - On main/trunk: If you use trunk-based development, tag the commit on the main branch that has passed all automated tests and has been manually verified in a staging environment.
- Check CI status: Only tag a commit whose CI pipeline is green. If the pipeline is flaky, re-run it and confirm the commit passes consistently.
- Verify the changelog: Ensure the commit includes the final changelog entry and version number bump. If the version bump is a separate commit, tag the commit after that bump, not before.
- Include the lockfile: For applications with dependencies, confirm that the lockfile (e.g.,
package-lock.jsonorGemfile.lock) is committed and reflects the exact dependency set you tested. Tagging a commit with an outdated lockfile can lead to unreproducible builds.
In practice, the tagged commit is often the same as the last commit on the release branch after the final merge. For example, if you are releasing version 1.4.0, you might create a release/1.4.0 branch from develop, fix bugs there, merge it into main, and then tag v1.4.0 on main at that merge commit. Some teams tag the merge commit itself; others tag the last commit on the release branch before the merge. The key is consistency—pick a convention and document it.
Common Mistakes and How to Avoid Them
Several pitfalls trip up teams when tagging releases:
- Tagging too early: You tag a commit that looks ready, but a last-minute fix is merged afterward. The tag now points to an outdated build. Solution: wait until the release is frozen and all changes are in.
- Tagging a feature branch commit: If you tag a commit on a feature branch that was never merged, the tag is orphaned. Solution: always tag on the main or release branch.
- Moving a tag: If you realize you tagged the wrong commit, some teams delete and recreate the tag. This is dangerous if others have already fetched it, because they will have the old tag cached. Solution: avoid moving tags; if you must, communicate clearly and force-update with caution.
- Not tagging at all: Some teams rely on branch names or timestamps to identify releases. This makes it impossible to reproduce an exact build. Solution: always tag, even for internal pre-releases.
- Tagging without a version bump: If the code has not been updated to the new version number, the tag will be misleading. Solution: ensure the version file is updated in the same commit or a commit immediately before the tag.
Semantic Versioning and Tag Naming
Your tag name should follow a clear, predictable pattern. The most common is Semantic Versioning (SemVer), which uses MAJOR.MINOR.PATCH (e.g., 2.1.0). Tags typically prefix with v to distinguish them from other refs: v2.1.0. This is a widely accepted convention, though not mandatory. Whatever you choose, be consistent.
For pre-releases, SemVer suggests suffixes like -alpha.1, -beta.2, or -rc.1. These are useful for testing and can be tagged as well, e.g., v2.1.0-rc.1. The same rules apply: tag the commit that represents that specific pre-release state, not a later commit.
Release Branches vs. Main Branch Tagging
There are two dominant strategies for when to tag:
- Git Flow: You have a
developbranch for integration and amainbranch for stable releases. When a release is ready, you create arelease/x.y.zbranch, stabilize it, then merge tomainand tag there. This gives a clear separation between development and production code. - Trunk-Based Development: You work directly on
main(or a short-lived feature branch). You tag a commit onmainthat has passed all checks. This is simpler but requires strong CI and feature flags to keepmainalways releasable.
Both are valid; the choice depends on your team's workflow and release frequency. The important thing is that the tagged commit is the one you actually deploy. If you use Git Flow, tagging on the release branch before the merge into main can be problematic because the merge may introduce changes (e.g., a merge commit) that are not in the tag. Therefore, tag after the merge, on main.
Frequently Asked Questions
Should I tag the merge commit or the last commit before merging?
Tag the merge commit on the main branch, because that is the commit that actually contains all the changes from the release branch. If you tag the last commit on the release branch, the tag does not include the merge itself, which might have resolved conflicts or added a version bump. The merge commit is the true final state.
What if I need to tag a hotfix after a release?
Create a hotfix branch from the tagged commit, apply the fix, test it, then merge it back to main and tag a new patch version (e.g., v1.2.1). Do not move the existing tag; create a new one. This preserves the history of the original release and the fix.
Can I tag a commit that is not on the main branch?
Yes, you can tag any commit, but it is not recommended for production releases. A tag on a feature branch is hard to find and may not be included in the main line. For internal testing, you can tag pre-release commits on any branch, but for public releases, always tag on main or a release branch that is merged into main.
How do I know if a commit is safe to tag?
Check that the commit has a green CI pipeline, has passed manual QA in a staging environment, and includes the final version bump and changelog. If any of these are missing, do not tag it. You can also use a release checklist in your issue tracker to ensure all criteria are met.
What is the difference between a lightweight and annotated tag?
A lightweight tag is just a pointer to a commit, with no extra metadata. An annotated tag stores the tagger's name, email, date, and a message. For releases, always use annotated tags (git tag -a v1.0.0 -m "Release v1.0.0") because they provide a permanent record of who and why, which is valuable for auditing.
Should I tag every build or only stable ones?
Tag every build that you deploy to any environment, including staging and production. For internal builds, you can use a simple tag like build-1234 or a CI-generated tag. For public releases, use a SemVer tag. This makes it easy to reproduce any environment state.