Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 47

Tagging Releases and Milestones with Git

Recommended resources

Hello! Welcome to your seventh lesson in the "Collaboration with GitHub" module.

In our previous lesson, you mastered the GitHub Flow, learning how to take a feature from a new branch all the way to a merged Pull Request in the main branch. This workflow ensures that your main branch is always stable and deployable.

Today, we'll address the next logical step in the software lifecycle: marking these stable points as official releases. This lesson will teach you how to use Git tags to mark release versions and important milestones. In a DevOps context, tagging is the foundation of versioning, release management, and automated deployments.

1. What is a Git Tag?

While a branch is a pointer that moves forward as you add new commits, a tag is a pointer that is fixed to a specific commit. Think of it like a permanent bookmark in your project's history. Its primary purpose is to capture a point in time, most often a software release (e.g., v1.0.0, v2.1.4).

What are Git Tags?
This diagram illustrates how tags like `v1.0` and `v1.1` are anchored to specific commits on the master branch, creating permanent markers in the project's history.

When you push tags to a remote repository like GitHub, they form the basis of the "Releases" feature, which provides a formal record of your project's versions.

GitHub Repository Releases Section
On a GitHub repository page, the "Releases" section, highlighted here, lists all the tagged versions of the project, making it easy for users to find and download specific releases.

2. Annotated vs. Lightweight Tags

Git offers two kinds of tags. Understanding the difference is crucial for professional use.

How to Use Git Tags for Versioning Releases

The article 'How to Use Git Tags for Versioning Releases' from Algocademy clearly explains the two types of tags: lightweight and annotated. For creating official releases, one type is strongly recommended.

Please read the section titled '2. Types of Git Tags'. Focus on understanding why annotated tags, which store extra metadata, are considered the best practice for public releases.

To summarize, for any work in a professional or team setting, you should always use annotated tags. They are stored as full Git objects and contain crucial metadata:

  • The name of the person who created the tag.
  • The date the tag was created.
  • A tagging message, similar to a commit message.

Lightweight tags are just simple pointers and are best reserved for temporary, private use.


3. Semantic Versioning: Naming Your Releases

Before we create a tag, we need a naming convention. The industry standard is Semantic Versioning (SemVer). It provides a clear, consistent way to name your releases that communicates the nature of the changes.

The format is MAJOR.MINOR.PATCH (e.g., v1.2.3):

  • MAJOR (1): Incremented for incompatible API changes (breaking changes).
  • MINOR (2): Incremented for adding functionality in a backward-compatible manner.
  • PATCH (3): Incremented for backward-compatible bug fixes.

How to Release Code With Github

To see why SemVer is so important and how it's used in real-world projects, let's watch this short video from Kahan Data Solutions. It explains the concept of releases on GitHub and breaks down the meaning of Semantic Versioning.

Watch the first 2 minutes and 44 seconds. Pay close attention to the breakdown of the MAJOR.MINOR.PATCH structure and what each number signifies.

Adopting SemVer is a critical DevOps practice. It allows both humans and automated systems (like CI/CD pipelines) to understand the impact of a new version at a glance.


4. Hands-On: Creating and Managing Tags with Git

Now, let's get practical. The following video provides an excellent step-by-step guide to the core tagging commands. We'll walk through the most important parts.

Git and GitHub Beginner Tutorial 7 - Git Tags - what, why, when and how

The video 'Git and GitHub Beginner Tutorial 7 - Git Tags' from Automation Step by Step provides a clear, hands-on demonstration of the entire tagging workflow, from creation to deletion.

We will watch specific segments of this video. For now, just have it ready. I will guide you through the relevant parts below.

Step 1: Listing and Creating Tags

First, let's see how to list existing tags and create a new one. Assume we've just merged a feature and are ready to create v1.0.0.

  1. List existing tags:
    # This will show all tags in your local repository
    git tag
    
  2. Create an annotated tag: This command creates an annotated tag named v1.0.0 on the most recent commit (HEAD).
    git tag -a v1.0.0 -m "Initial release version 1.0.0"
    
    • -a specifies that it's an annotated tag.
    • -m provides the mandatory tagging message.

Watch the video from 01:05 to 03:03 to see this in action, including the difference between creating a lightweight and an annotated tag.

Step 2: Pushing Tags to the Remote

By default, git push does not send tags to your remote repository. You must do so explicitly.

  1. Push a single tag:
    git push origin v1.0.0
    
  2. Push all local tags at once:
    git push origin --tags
    

Watch the video from 03:38 to 05:00 to see how pushing a tag makes it visible on the remote repository (e.g., GitHub).

Step 3: Tagging a Past Commit

Sometimes you need to tag a commit that isn't the most recent one. For example, you might have forgotten to tag a release.

  1. Find the commit hash: Use git log to find the hash of the commit you want to tag. You only need the first 7-10 characters.
    git log --oneline
    # output:
    # 9fceb02 feat: Add user authentication
    # 3f2a1d8 fix: Correct spelling in README
    # ...
    
  2. Tag the specific commit:
    git tag -a v0.9.0 3f2a1d8 -m "Tagging pre-release for README fix"
    

Watch the demonstration in the video from 09:00 to 10:44 to see how this is done.

Test your understanding!

Your team has just fixed a critical security bug. The commit hash is a1b2c3d, and the current version of your software is v2.1.4. According to Semantic Versioning, what should the new version be, and what is the full command to create the appropriate annotated tag for this specific commit?

Show answer

The new version should be v2.1.5, because a backward-compatible bug fix increments the PATCH number.

The command is:
git tag -a v2.1.5 a1b2c3d -m "Release v2.1.5: Security patch for user authentication vulnerability"


5. From Git Tags to GitHub Releases

Pushing a tag is just the start. On GitHub, you can enhance a tag by creating a formal Release. A Release allows you to add detailed release notes and attach binary files (like compiled code or installers).

How to Release Code With Github

Let's return to the 'How to Release Code With Github' video. It shows how to convert a pushed Git tag into a rich, user-friendly Release on the GitHub interface.

Watch from 2:44 to 6:21. Observe how you can choose a tag, write release notes using Markdown, and even mark a release as a 'pre-release' (e.g., for alpha or beta versions).


6. Managing Tags: Deleting and Checking Out

Deleting Tags

While tags are meant to be permanent, you can delete them if needed. This is a two-step process.

  1. Delete the local tag:
    git tag -d v1.0.0
    
  2. Delete the remote tag:
    git push origin --delete v1.0.0
    
    Use this command with caution, especially in a team environment.

Checking Out Tags and "Detached HEAD"

You can view the exact state of your project at a specific tag by checking it out:

git checkout v1.0.0

When you do this, Git will warn you that you are in a "detached HEAD" state. This means you are no longer on a branch. You are viewing a historical snapshot. If you make new commits here, they won't belong to any branch and can easily get lost.

Don't worry about this for now. It's a very important concept that we will dedicate our entire next lesson to understanding and managing.


Conclusion

You've now learned how to create permanent, meaningful markers in your project's history using Git tags. This is a fundamental skill for versioning, release management, and enabling CI/CD automation.

Key Takeaways:

  • Git tags are fixed pointers to specific commits, used to mark releases.
  • Annotated tags (git tag -a) are the standard for releases because they store valuable metadata.
  • Semantic Versioning (MAJOR.MINOR.PATCH) is the professional standard for naming your releases.
  • Tags must be explicitly pushed to the remote repository (git push origin --tags).
  • On GitHub, a tag can be enhanced into a Release with detailed notes and binary files.
  • Checking out a tag puts you in a "detached HEAD" state.

In our next lesson, we will dive deep into the "detached HEAD" state, learning exactly what it means and how to safely navigate and work from these historical points in your repository.