DEV Community

Cover image for Structure of a Good Git Commit
Mehedi Hasan
Mehedi Hasan

Posted on • Edited on

Structure of a Good Git Commit

Writing clear and professional Git commits is more than a habit—it’s a skill that makes collaboration smoother, code history readable, and debugging easier. Here’s a concise guide to crafting quality commits.

🔹 Structure of a Good Commit

A professional commit usually consists of:

  • Type – what kind of change it is (feature, fix, docs, etc.)
  • Short message – 50 characters max, written in imperative tone (e.g., “Add login validation”)
  • Optional detailed description – wrap text at 72 characters for readability, explaining why the change was made

🔹 Common Commit Types

feat:   Adding a new feature

fix:    Bug fix

docs:   Documentation-only changes

style:  Formatting, missing semicolons, whitespace

refactor:   Code change that neither fixes a bug nor adds a feature

test:   Adding or updating tests

chore:  Maintenance tasks (configs, dependencies) 
Enter fullscreen mode Exit fullscreen mode

🔹 Good commits

feat: add user authentication

fix: resolve crash on profile update

docs: update README with installation steps

style: format code with Prettier

refactor: simplify dashboard component logic

test: add unit tests for login reducer

chore: update project dependencies
Enter fullscreen mode Exit fullscreen mode

🔹 Pro Tips

  • Always use imperative mood: e.g., Add feature instead of Added feature
  • Keep your commits focused: one commit = one purpose
  • Include context in the description when necessary

Top comments (0)