Mastering Git Commit Messages: Secrets, Tips, and Tricks (with examples)

David Garcia
3 min readOct 16
Work with Your History in Git Unit | Salesforce Trailhead

In the world of version control, effective communication is vital. Your commit messages are the bridge between you, your team, and your future self. Crafted with care, they can enhance collaboration, code comprehension, and project history.

Let’s dive into the secrets, tips, and tricks to elevate your “git commit” game.

Keep It Short and Sweet

A commit message should be concise yet informative.

Tip: Limit the first line to 50 characters and provide additional context in the body.

Bad: "Fixed a bug"
Good: "Fix issue with user registration"

Write in the Imperative Mood

Frame your commit messages as commands.

Tip: Start with a verb that indicates what the commit does.

Bad: "Fixing bug in the login page"
Good: "Fix bug in the login page"

Focus on What and Why

Explain what the commit changes and why it’s necessary.

Tip: Provide context on the problem and the solution.

Bad: "Added new feature"
Good: "Add user profile picture upload to enhance personalization"

One Commit, One Purpose

Each commit should address a single logical change.

Tip: Avoid mixing unrelated changes in one commit.

Bad: "Fixed bug and updated documentation"
Good: "Fix issue with search functionality"

Reference Issues and Pull Requests

Link commits to relevant issues or pull requests.

Tip: Use keywords like “Fixes,” “Closes,” or “Resolves” to close issues automatically.

Bad: "Implemented payment gateway"
Good: "Fix #123: Implement payment gateway"

Be Mindful of Line Length

Keep commit lines and body text within a readable length.

Tip: Wrap lines at 72 characters to maintain readability in various tools.

Bad: "Refactor authentication…
David Garcia

Senior Software Engineer, Backend, NodeJS & Symfony developer, workaholic, passionate for new technologies and OSS contributor. https://linktr.ee/davidgarciacat