Master Git & GitHub From Scratch

Clear, practical, and structured lessons designed to take you from Git fundamentals to real-world GitHub collaboration.

Tagging Releases

In Git, tagging releases means marking specific points in your repository's history as important milestones, such as software releases or production deployments. A tag like v1.0.0 identifies a particular commit.

Unlike branches, tags are intended to identify a specific point in history rather than move forward as new commits are created.


1. Types of Tags

Annotated Tags

Annotated tags are stored as full objects in Git. They contain the tagger's name, email, date, a message, and can be cryptographically signed. They are recommended for release versions.

git tag -a v1.0.0 -m "Initial production release"
Lightweight Tags

Lightweight tags are simple references to a specific commit. They do not contain the additional tagger information and message stored in an annotated tag.

git tag v1.0.0-lw

2. Common Tagging Commands

Tag a Previous Commit

You can tag an older commit by supplying its commit hash.

git tag -a v1.0.0 9f25d2b -m "Tagging an older commit"

Replace 9f25d2b with the actual commit hash from your repository.

List All Existing Tags
git tag

Lists the tags available in your local repository.

Push a Specific Tag
git push origin v1.0.0

Publishes the specified tag to the remote repository. A regular git push does not normally publish all local tags automatically.

Push All Local Tags
git push origin --tags

Pushes all local tags that have not already been transferred to the remote.

Important: Before pushing all tags, verify that you intend to publish them all to the remote repository.
Delete a Local Tag
git tag -d v1.0.0
Delete a Remote Tag
git push origin --delete v1.0.0

Deleting a remote tag removes it from the remote repository. It does not automatically delete copies of that tag from other developers' local repositories.


3. Semantic Versioning (SemVer)

Many development teams use Semantic Versioning in the format:

vMAJOR.MINOR.PATCH
Version Part Meaning Example
Major Introduces incompatible changes. v2.0.0
Minor Adds backward-compatible functionality. v1.1.0
Patch Includes backward-compatible bug fixes. v1.0.1

4. Example: Tag a Release

Use the following sequence to tag a release and publish it to your remote repository.

Step 1: Check Your Commits
git log --oneline
Step 2: Create an Annotated Tag
git tag -a v1.0.0 -m "Release version 1.0.0"
Step 3: Verify the Tag
git show v1.0.0
Step 4: Publish the Tag
git push origin v1.0.0
Key Takeaway: Use annotated tags for release milestones, choose meaningful version numbers, and push tags explicitly when you want to publish them to your remote repository.