How to Manage Version Number in Git
This article outlines how you can manage your version number in Git. We will employ semantic versioning since it is the most widely used versioning scheme.
Manage Version Number in Git
Before we can start managing, let’s first define some terms.
Semantic Versioning
Semantic versioning is simply a numbering schema. We use it as an industry-standard software development indicator to show the degree of changes released since the prior release.
It is a clear and concise method of indicating the level of changes and is widely used by developers.
A semantic version number has three parts:
- The major part
- The minor part
- The patch number
We will not go into much as defining every part and its functionality, but here is a quick chart.
Semantic versioning requires us to double-check your version number before releasing code. This makes the schema ideal for combining Git tags.
Git Tags
We use Git tags to mark a commit as meaningful. Git has two types of tags.
- Lightweight tags
- Annotated tags
A lightweight tag is a simple-named pointer. Here is an example.
On the other hand, annotated tags contain more details about the commit. We can use the git tag
command with the -a
flag to mark it as an annotated tag and use the -m
flag to provide a description.
Here is an example.
Annotated Git Tags + Semantic Versioning
Employing annotated Git tags and semantic versioning allows us to mark commits in our repository with version numbers. Several Git products with interfaces support semantic versions for Git tags.
Here is an example on Mac.
As illustrated below, we can run the git tag
command to tag commits with the semantic versioning scheme.
$ git tag - "v1.2.0-beta" -m "version v1.2.0-beta"
The command above will add a v1.2.0-beta
tag to our repository. To view the details of a tag, we can run:
$ git show v1.2.0-beta
In a nutshell, semantic versioning combined with annotated Git tags provides the perfect way to indicate the level of changes in our codebase. We have covered how to use your repository’s semantic versioning with Git tags.
John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
LinkedIn