git
commit messages
programming
best practices
version control

Git Commit Messages 50/72 Formatting

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Understanding Git Commit Messages: 50/72 Formatting

When contributing to software development projects, the significance of clear and descriptive git commit messages cannot be understated. The 50/72 rule is a popular formatting guideline that helps maintain clarity, communication, and discipline when writing these messages. In this article, we’ll break down this formatting style, provide insights into its use, and explore its advantages.

The 50/72 Rule Explained

The 50/72 rule stipulates that:

  • The subject line (the first line of your commit message) should be no longer than 50 characters.
  • The main content or body (any subsequent lines) should be wrapped at 72 characters or less per line.

Why 50/72?

  1. Clarity and Brevity:
    • The 50-character limit for the subject makes developers summarize the commit succinctly.
    • Easier for others to understand the general idea without diving into full commit details.
  2. Readability:
    • The 72-character limit for body lines ensures the message is easily readable in various interfaces such as terminal windows, GitHub UI, and others without line wrapping.
  3. Consistency:
    • Predictable formatting helps teams maintain a consistent history, making project collaboration more efficient.

Writing Effective Commit Messages

Components of a Well-Formatted Commit Message

  1. Subject Line:
    • Use imperative mood (e.g., "Fix bug" instead of "Fixes bug").
    • Be concise yet descriptive enough to understand the commit's intent.
  2. Blank Line:
    • After the subject line, include a blank line before the body. This helps tools easily parse the commit message.
  3. Body:
    • Explain what and why the change was made, not how (the code changes themselves will show the 'how').
    • Split thoughts into paragraphs with additional blank lines.
    • If applicable, note any backward compatibility issues, side effects, or references to bug IDs or external discussions.

Example

Below is an example of a properly formatted commit message following the 50/72 rule:

  • Single Focus: Commit messages should convey a single change, ensuring commits remain small and manageable.
  • Version Control Systems (VCS) Friendly: Align your messages with the capabilities of VCS tools, adopting discipline in message composition.
  • Automation Compatible: Clear commits help automation tools better parse and trigger actions like deployments or tests.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.