DEV Community

Cover image for 🚀 Clean Commit Messages: Why & How
Mhammed Talhaouy
Mhammed Talhaouy

Posted on

🚀 Clean Commit Messages: Why & How

Writing clear, structured commit messages makes collaboration smoother, code reviews easier, and project history understandable. Here's a simple guide I follow:⁣

Commit Message Structure


<type>(<scope>): <short description>⁣
Enter fullscreen mode Exit fullscreen mode



  • type → the kind of change⁣
  • scope → optional, the affected module⁣
  • description → concise summary (imperative mood)⁣ ⁣ ### Common Types⁣ ⁣
  • feat: → new features⁣
  • fix: → bug fixes⁣
  • chore: → maintenance, build updates, configs⁣
  • docs: → documentation⁣
  • refactor: → code improvements without changing behavior⁣
  • style: → formatting, linting, whitespace⁣
  • test: → adding/updating tests⁣ ⁣ Example:⁣ ⁣
feat(auth): add login with Google⁣
fix(api): handle null pointer on user fetch⁣
chore: update dependencies⁣
Enter fullscreen mode Exit fullscreen mode



Best Practices

  1. Imperative tone – describe what the commit does:⁣ ✅ fix(ui): remove extra padding on button⁣ ❌ fixed padding issue⁣ ⁣
  2. Keep subject short – ≤ 50 characters⁣ ⁣
  3. Use body for details – explain why, not just what:⁣ ⁣
   feat(auth): add password reset⁣
⁣
   - Added endpoint /auth/reset-password⁣
   - Updated email templates⁣
   - Closes #123⁣
Enter fullscreen mode Exit fullscreen mode




Clean commits = better teamwork & smoother code history! 🛠️💡⁣

Top comments (2)

Collapse
 
amarantess profile image
Gabriel Amarantes

It is very useful, thanks!

Collapse
 
tal7aouy profile image
Mhammed Talhaouy

You are welcome :)