Mastering Semantic Commits: Write Better Git Messages for Your Projects
👋 Hey, I'm a Frontend Developer passionate about building clean, user-friendly interfaces. 🚀 Learning and sharing everything from React, JavaScript, HTML/CSS to advanced topics like Data Structures, Algorithms & System Design. 💻 Documenting my journey from fundamentals to becoming a top-tier developer — one blog at a time. 📚 Join me as I break down complex topics into easy, practical lessons — with GitHub repos, code snippets, and real-world examples. 🔁 Consistent growth, community learning, and aiming high!
Introduction
If you’re a developer working with Git, you know that commit messages are important—but how many times have you struggled to understand a vague commit like:
fixed stuff
update
bug fix
Semantic commits are a way to bring clarity, consistency, and automation to your commit messages by following a simple, structured format. This not only helps your team understand what changed and why but also powers automatic changelog generation and versioning.
In this post, I’ll take you through the basics of semantic commits, why they matter, and how to write them — step by step. Plus, I’ve created a GitHub repo with detailed notes and examples that you can refer to anytime.
What Are Semantic Commits?
Semantic commits are commit messages that follow a standard format, making the purpose of each commit clear at a glance.
The basic structure looks like this:
<type>(<scope>): <description>
type — what kind of change it is (
featfor new features,fixfor bug fixes, etc.)scope — optional area of the code affected (
auth,api,ui)description — short summary of the change
Example:
feat(auth): add JWT token authentication
fix(login): handle empty password error
docs(readme): update installation instructions
Why Use Semantic Commits?
Clear communication: teammates quickly know what was done.
Automation: enables tools like semantic-release to auto-generate changelogs and bump versions.
Consistency: a unified style across the project.
Better tracking: search commits by type to find features, fixes, docs, etc.
How to Write Semantic Commits
Use one of the common types:
feat,fix,docs,style,refactor,test,choreInclude a scope if relevant.
Write a clear, concise description in imperative tense (e.g., “add” not “added”).
For complex changes, add a body explaining why the change was made.
Use a footer for references or breaking changes.
Example:
feat(api): add user profile endpoint
This endpoint returns user data along with profile pictures and social links.
Closes #42
Semantic Commits + Semantic Versioning
Semantic commits also help automate Semantic Versioning:
feat:triggers a minor version bumpfix:triggers a patch version bumpBREAKING CHANGE:triggers a major version bump
This makes release management much easier.
Tools to Enforce Semantic Commits
commitlint: checks commit message format.
Husky: runs pre-commit hooks to enforce rules.
semantic-release: automates version bumping and changelogs.
Learn More — GitHub Repo with Notes & Examples
I’ve put together detailed notes and examples on semantic commits in this GitHub repo, which you can use as a quick reference:
🔗 Semantic Commits Notes & Examples Repo
Feel free to star, fork, and contribute!
Final Thoughts
Using semantic commits might feel like a small detail, but it can dramatically improve your project’s workflow, clarity, and automation capabilities.
Start using semantic commits today and see the difference!
✍️ Written by Krishan — follow me on Twitter and GitHub and Linkedin
💡 Check out the current code examples and notes repo: GitHub
📝 Read more on my blog: Hashnode