How to improve your commit messages to collaborate better with your team
Let's learn some of the best practices for writing quality commit messages.
Be specific and clear
Clearly mention what you did in the commit message. If you are fixing a bug, mention the bug number in the commit message. If you are adding a new feature, mention the feature name in the commit message.
git commit -m "fix(#123): Resolve issue with user profiles not rendering"
Provide context
Address 'why' this change has been done,
# Bad - No context
git commit -m "Updated files"
# Good - With context around user profiles
git commit -m "fix(#123): Resolve issue with user profiles not rendering"
Keep it short and use imperative mood
# Bad
git commit -m "I have updated dependency for security"
# Good - have context, short and imperative mood
git commit -m "chore: Update dependencies for better security in user endpoints"
Use emojis (bonus)
I like it when people use emojis in commit messages. It makes it more fun to read. Here are some of the emojis I use in my commit messages.
:bug:
- When fixing a bug:sparkles:
- When adding a new feature:art:
- When improving the format/structure of the code:racehorse:
- When improving performance:memo:
- When writing docs:white_check_mark:
- When adding tests:lock:
- When dealing with security:arrow_up:
- When upgrading dependencies:arrow_down:
- When downgrading dependencies:shirt:
- When removing linter warnings
Tagging for improving clarity
fix
- when fixing a bugfeat
- when adding a new featurechore
- when updating build tasks, package manager configs, etcdocs
- when writing docsstyle
- when formatting code, updating linter configs, etc; no code changerefactor
- when refactoring code; no feature or bug fixperf
- when improving performancetest
- when adding tests; no feature or bug fixbuild
- when making changes to build scripts, CI configs, etcci
- when making changes to CI configs, etcrevert
- when reverting changes
What if you want to use multiple tags? You can use []
to add multiple tags.
git commit -m "[feat][#123]: Add new user profile page"
Example commit message,
fix: Resolve issue with login button not redirecting to dashboard
chore: Refactor API calls for improved error handling
style: Adjust button padding and font size for better mobile responsiveness
feat: Introduce user authentication via OAuth 2.0
docs: Clarify usage of config parameters in README
test: Add unit tests for user registration module
Hope you learned something new today. Happy coding and ask me any questions on my Twitter š.