How to write good commit messages in Git
Writing good commit messages in Git creates clear project history that helps team members understand changes and makes debugging and code reviews more efficient. As the creator of CoreUI, a widely used open-source UI library, I’ve written thousands of commit messages across multiple repositories and established clear messaging standards for enterprise development teams. From my expertise, the most effective approach is using imperative mood with descriptive subjects and optional body text for complex changes. This method provides clear change documentation and improves team collaboration through better communication.
Use imperative mood with clear, descriptive subjects that explain what the commit accomplishes.
# Good commit messages
git commit -m 'Add user authentication middleware'
git commit -m 'Fix memory leak in data processing'
git commit -m 'Update dependencies to latest versions'
# With body for complex changes
git commit -m 'Refactor user service for better performance
- Extract validation logic into separate functions
- Implement caching for frequently accessed data
- Add comprehensive error handling
- Update tests to cover new functionality'
# Follow conventional format
git commit -m 'feat: add dark mode toggle component'
git commit -m 'fix: resolve button alignment in mobile view'
git commit -m 'docs: update API documentation'
Good commit messages use imperative mood (‘Add feature’ not ‘Added feature’), keep the subject line under 50 characters, and explain what the commit does rather than what was done. Use the body for detailed explanations when changes are complex or need context.
Best Practice Note:
This is the same commit message format we use in CoreUI repositories for clear project history and efficient team collaboration across development cycles.