Mastering Git Commits: Telling the Story of Your Code

October 18, 2024

Mastering Git Commits: Telling the Story of Your Code

A Git repository is more than just a backup system; it's the historical record of your project's evolution. When bugs arise or features need tweaking, a messy commit history full of "wip" and "fixed stuff" is completely useless.

Good commit messages provide context that the code itself cannot express. They answer the "why" behind a change, not just the "what".

Why commit messages matter

  • They speed up the reviewing process for your teammates.
  • They make git bisect a powerful tool for finding bugs.
  • They serve as long-term documentation for architectural decisions.
  • They allow auto-generation of clean changelogs.

Commit message rules

  1. Capitalize the subject line and do not end it with a period.
  2. Keep the subject line under 50 characters.
  3. Use the imperative mood (e.g., "Add user login" instead of "Added user login").
  4. Separate the subject from the body with a blank line.
  5. Use the body to explain what and why, not how.

Wrap-up

Treat your Git history with respect. Taking an extra 30 seconds to write a thoughtful commit message is an investment that pays massive dividends in the future.

GitHub
LinkedIn
Instagram
youtube