Commit Message Templates
Subject line length, body (what + why), footers — Closes, Co-authored-by
Commit message structure
- Subject: imperative, 50 chars max — what changed
- Body: (optional) blank line, then WHY — not HOW
- Footer: Closes #N, Fixes #N, Co-authored-by: Name <email>
- Blank line is required between subject and body
- The diff shows HOW — the body should explain context and motivation
Question 0 of 5
The Git commit subject line recommendation is to keep it under 50 characters. Why?
Tools truncate or wrap at roughly 50–72 characters. Subject line guidelines:
- 50 chars: ideal — fits neatly in
git log --onelineand GitHub's commit list - 72 chars: hard limit — text beyond this wraps awkwardly in email and terminal output
- git log --oneline shows only the subject, making length critical for scannability
A commit message body should explain what and why. What should it not explain?
How the code works — the diff already shows that. Body guideline:
- Explain WHY: "The old approach caused N+1 queries on every page load"
- Explain WHAT: "This commit adds eager loading for user.orders"
- Explain TRADE-OFFS: "This increases memory usage by ~5MB on startup"
- Skip HOW: "Changed the for loop to a map and reduced array allocation by using..." — this is in the diff
Which commit message footer correctly closes a GitHub issue?
Closes #142 — automatically closes the referenced GitHub issue when the commit merges. GitHub-recognised closing keywords:
Closes #N,Close #N,Closed #NFixes #N,Fix #N,Fixed #NResolves #N,Resolve #N,Resolved #N
See #N— links without closingRelated to #N— links without closing
Closes owner/repo#N.You need to attribute a commit to a co-author. Which footer syntax is correct?
Co-authored-by: Name <email> is the correct GitHub-recognised footer. Co-author attribution:
- Must be in the commit body/footer (after a blank line from the subject)
- Exact format:
Co-authored-by: Name <email@example.com> - Multiple co-authors: add one line per person
- GitHub displays co-authors on the commit page and counts their contributions
Which is the best-formatted complete commit message (subject + body)?
fix(auth): prevent login with expired tokens with a clear body. Why Option B wins:
- ✅ Subject (44 chars): under 50, imperative, scoped
- ✅ Blank line: separates subject from body (required by Git)
- ✅ Body explains WHY: "only checking signature, not expiry claim"
- ✅ Context: "tokens expired more than 24 hours ago" — quantifies the problem
- ✅ Footer: "Closes #88" — links to the issue