Semantic Versioning with Tags in Git Tutorial 🎯

beginner
5 min

Semantic Versioning with Tags in Git Tutorial 🎯

Welcome to this comprehensive guide on Semantic Versioning with Tags using Git! This tutorial is designed for both beginners and intermediates, so let's get started. 📝

Understanding Semantic Versioning 📝

Semantic Versioning (SemVer) is a standard way to format the version numbers for your projects. It helps maintain compatibility as your project evolves, making it easier for developers to understand changes and decide whether to upgrade.

Major, Minor, Patch Versions 📝

A SemVer version consists of three parts: MAJOR.MINOR.PATCH. Each part represents a different type of change:

  1. Major (MAJOR): Indicates breaking changes that may cause existing functionality to stop working.
  2. Minor (MINOR): Represents new features, improvements, and bug fixes that are backwards-compatible.
  3. Patch (PATCH): Signifies fixes for bugs without affecting existing features or deprecating old APIs.

Tagging Releases in Git 📝

In Git, we use tags to mark specific points in our project's history. This is particularly useful for SemVer, as we can associate a tag with each release.

Creating a Tag 💡

To create a tag, follow these steps:

bash
$ git tag v1.0.0 # Create a tag with the name v1.0.0 $ git push origin v1.0.0 # Push the tag to the remote repository

Listing Tags 💡

To see all the tags, use the following command:

bash
$ git tag

SemVer and Git Workflow 💡

Now, let's combine SemVer and Git workflow. We'll use the GitFlow branching model for this example.

  1. Develop Branch: Develop new features, fix bugs, and prepare for a new release.
  2. Feature Branch: Create a branch for each new feature or improvement.
  3. Release Branch: Once the development is complete, create a release branch from the Develop branch, perform final testing, and prepare the release.
  4. Tagging: Once the testing is complete, create a tag for the new release on the release branch.
  5. Merge: Merge the release branch back into the Develop and Master branches.

Real-World Example 💡

Let's consider a simple project with a version 0.1.0. We'll create a new feature (fix a bug) and then release it.

Creating a Feature Branch 💡

bash
$ git checkout -b fix-bug

Making Changes and Committing 💡

bash
$ git add . $ git commit -m "Fixed a bug related to login"

Creating a Release Branch 💡

bash
$ git checkout -b release/v1.0.1 $ git merge fix-bug

Tagging the Release 💡

bash
$ git tag v1.0.1 $ git push origin v1.0.1

Merging Back into Develop and Master 💡

bash
$ git checkout develop $ git merge release/v1.0.1 $ git push origin develop $ git checkout master $ git merge release/v1.0.1 $ git push origin master

Quiz 💡

Quick Quiz
Question 1 of 1

What does the `MAJOR` part in SemVer represent?

Happy learning, and remember, practice makes perfect! 🤓