Harry Yates

I'm a web developer focused on TypeScript, React, and Three.js.

Semantic Versioning with Git Tags

Fri, 28th Jun 2024

In software development, tracking changes and updates can be challenging. Semantic versioning can help.

By following a structured versioning system, developers can communicate changes effectively, ensuring compatibility and clarity.

JFK

What is Semantic Versioning?


Semantic versioning (SemVer) is a versioning scheme that uses a three-part number format: `MAJOR.MINOR.PATCH`. Each part of the version number signifies the scope and impact of changes:


- MAJOR version increments when you make incompatible API changes.
- MINOR version increments when you add functionality in a backwards-compatible manner.
- PATCH version increments when you make backwards-compatible bug fixes.

For instance, version `1.2.3` breaks down as follows:


- MAJOR Incompatible changes
- MINOR New features, no breaking changes
- PATCH Bug fixes

Why Use Semantic Versioning?


Semantic versioning provides clear guidelines for version increments, which helps both the developers and the software users. It ensures:


- Clarity: Everyone understands the significance of each version.
- Compatibility: Users know what to expect in terms of API compatibility.
- Structure: Provides a consistent way to handle and communicate updates.

Implementing Semantic Versioning with Git Tags


Git tags are a simple yet powerful way to manage and track your project versions. Let’s go through the steps to implement semantic versioning using Git tags.

Step-by-Step Guide


1. Commit Your Changes:
After making changes, commit them with a descriptive message.

git commit -m "Add new feature to handle pets"

2. Tag the Version:
Use Git to create a new tag for the version.

git tag -a v1.0.0 -m "Initial release with pet handling feature"

3. Push the Tags to Remote:
Ensure your tags are pushed to the remote repository.

git push origin master --tags

Automating with npm


If your project uses npm, you can automate versioning updates directly in `package.json`. For example, to increment the minor version:


npm version minor


This command updates the version in `package.json` and creates a corresponding Git tag.