Git Tags
Tags are like permanent bookmarks in your project history. Unlike branches, which change as you add new commits, tags are stationary. They are primarily used to mark specific release points (milestones) in your project, such as v1.0.0 or v2.1.5.
1. Types of Tags
Git supports two types of tags, each serving a different purpose:
| Type | Metadata | Best For... |
|---|---|---|
| Lightweight | Just a commit checksum (no extra info). | Temporary or private bookmarks. |
| Annotated | Handled as full objects in the Git database. Includes tagger name, email, date, and a message. | Public Releases / Production versions. |
2. Core Commands
List Available Tags
git tagCreate a Lightweight Tag
git tag v1.0.0-lwCreate an Annotated Tag (Recommended)
git tag -a v1.0.0 -m "Release version 1.0.0 stable"Tagging a Past Commit
If you forgot to tag a release, you can tag a past commit by providing the hash:
git tag -a v0.9.0 9fceb02 -m "Back-tagging old version"3. Remote Synchronization
By default, the git push command does NOT transfer tags to remote servers. You must push them explicitly.
- Push a specific tag:
git push origin v1.0.0 - Push all local tags:
git push origin --tags
4. Deleting & Navigating
Deleting Tags
To remove a tag, you must delete it locally AND update the remote:
- Local:
git tag -d v1.0.0 - Remote:
git push origin --delete v1.0.0
Checking Out a Tag
You can view the code at a specific tag, but you will be in a "detached HEAD" state:
git checkout v1.0.0[!IMPORTANT] Annotated is the Standard For DevOps and production environments, always use annotated tags (
-a). They provide the traceability and checksum validation required for professional deployment pipelines.