How to Write Git Commit Messages Like a Pro
Source: Dev.to
What is Git?
Git is a distributed version control system that manages versions of source code or data. Programmers use it to collaborate on projects efficiently.
Git lets you work locally, track changes to files, and push those changes to remote repositories like GitHub or Bitbucket for collaboration.
How to Commit
A commit is made by running:
git commit -m "some-message"
The -m flag denotes message and "some-message" contains the details of what you are committing. Commit messages should prioritize clarity, brevity, and readability over long paragraphs or perfect grammar.
Common Commit Message Tags
Using standard tags makes Git history clear and helps your team understand the purpose of each change.
-
feat– adds or changes functionality that matters to users.
feat: add GitHub OAuth login -
fix– fixes a bug.
fix: handle API rate limits -
docs– only documentation changes (no code behavior changes).
docs: update README with setup instructions -
style– code style or formatting changes that do not affect logic or behavior.
style: fix indentation -
refactor– improves structure or readability without changing behavior.
refactor: simplify GitHub client logic -
test– adds, updates, or fixes tests only.
test: add unit tests for login -
chore– maintenance tasks that don’t affect application behavior (dependencies, configs, scripts).
chore: update GitHub Actions workflow -
revert– reverts a previous commit.
revert: undo login feature -
perf– changes that improve performance.
perf: optimize database queries -
build– changes that affect the build system or external dependencies.
build: update dependencies
Tip: Write your commits in the present tense.
Instead offeat: added login functionality, usefeat: add login functionality.
“Git commit messages are how we communicate to our future selves.”
Happy committing, and may your Git history be clean and understandable. 👋