Git Commit Message: Format, Rules and Examples

November 11, 2026 · 11 min read

Git Commit Message: Format, Best Practices, and Examples

A git commit message is the text you attach to a commit with git commit -m "Subject" or in the editor Git opens. Write a short subject line (about 50 characters), leave a blank line, then add a body that explains what changed and why. Use the imperative mood: "Fix login timeout", not "Fixed login timeout".

How Do You Commit With a Message in Git?

To make a git commit with message text in one step, use the -m flag. Wrap the message in quotes so your shell passes it as one argument:

git commit -m "Fix crash when config file is empty"

That records a commit whose whole message is that one line. For a subject plus a body, repeat the flag. The git commit documentation says multiple -m values are joined as separate paragraphs:

git commit -m "Fix crash when config file is empty" -m "The loader assumed at least one key and threw on an empty file. Treat an empty file as the default config instead."

Git stores that as a subject line, a blank line, then the body paragraph. Git doesn't wrap the body for you, so a long -m string stays one long line.

Run git commit with no message flag and Git opens your editor instead. Three more options are handy:

  • git commit -am "Subject" stages every tracked file you've modified, then commits. New, untracked files still need git add first.
  • git commit -F notes.txt reads the message from a file (-m can't be combined with -F, -c or -C).
  • git commit -v shows the staged diff below the message while you write. That diff isn't saved into the commit.

We prefer git commit -v for anything that needs a body. You see exactly what you're describing, and you can wrap lines properly instead of fighting shell quotes.

Git Commit Message Format: Subject, Blank Line, Body, Trailers

Every well-formed commit follows the same layout, with up to four parts. Here's a message that uses all of them:

Add retry with backoff to the payment webhook

The provider occasionally returns 503 during deploys, and we dropped
those events silently. Retry up to three times with exponential backoff,
then log the event ID so support can replay it by hand.

Fixes: #482
Co-authored-by: Sam Lee <sam@example.com>

The parts, top to bottom:

  1. Subject line. One line that summarises the change. Git treats it as the commit title, which git log --oneline shows.
  2. Blank line. Git's title runs up to the first blank line, so skip it and your second line joins the title.
  3. Body. Plain prose explaining what and why. Wrap it so it reads well in a terminal.
  4. Trailers. Key: value lines at the very end, after another blank line. Co-authored-by and Signed-off-by are the common ones, and GitHub also accepts Fixes: #482 as an issue-closing line.

A one-line message is fine for small, obvious changes like a typo fix. Add a body whenever a reviewer would ask "why?" after reading the diff.

What Makes a Good Git Commit Message? The 50/72 Rule and Imperative Mood

A good message lets someone scanning the history understand the change without opening the diff. Five habits get you most of the way there.

Keep the subject near 50 characters. The git-commit docs suggest a summary line of no more than 50 characters, and Git's own SubmittingPatches guide calls 50 a soft limit. Going to 60 won't break anything, but long subjects wrap awkwardly in git log --oneline and get shortened in many web commit lists.

Wrap the body at 72 columns. This one is common practice rather than a Git rule. It keeps the body readable in an 80-column terminal, where git log indents it by four spaces.

Write the subject in the imperative mood. SubmittingPatches asks you to describe changes "as if you are giving orders to the codebase". A quick test: the subject should complete the sentence "If applied, this commit will...". "Remove unused env vars" passes. "Removed unused env vars" doesn't.

Capitalise the subject and drop the trailing period. The period wastes a character and the subject is a title, not a sentence. (Git's own project uses lowercase after an area: prefix, so follow whatever your repository already does.)

Explain why in the body, not how. The diff already shows how. The body should record the reason, the trade-off and anything you ruled out.

The core git commit message best practice is consistency: pick these rules once, write them down in your README or contributing notes, and apply them everywhere. That's the same idea behind a Markdown style guide for docs. One limitation to accept: Git enforces none of it. A 300-character past-tense subject commits just fine, so the habit lives in code review or a hook.

Git Commit Message Examples: Bad vs Better

Most weak messages are vague, written in past tense or describe the file instead of the change. Here are typical rewrites:

Weak messageBetter message
fixed stuffFix crash when config file is empty
WIPAdd draft parser for CSV import
Update README.mdDocument the PORT environment variable
changes per reviewRename getUser to fetchUser for clarity
Fixed the bug where users could not log in after the password reset email expiredReject expired password reset tokens
miscBump lodash from 4.17.20 to 4.17.21

Notice what the better versions share. Each starts with a verb, names one change and makes sense without the diff. None of them mentions the file name unless the file is the point.

A bug fix that needs context reads like this:

Reject expired password reset tokens

Tokens were checked for a valid signature but never for age, so a
link from a month-old email still worked. Compare the issued-at time
against the 30-minute window and return 410 Gone when it's stale.

A dependency bump can stay short, with the reason in one line of body:

Bump lodash from 4.17.20 to 4.17.21

Pulls in the fix for the command injection in template().

When you run git revert, Git writes the message for you. Reverting a commit titled "Fix crash" produces:

Revert "Fix crash"

This reverts commit 68d0a34db4f8b6233d14bd8d16b2fec997f07a31.

Add a sentence below that line saying why you reverted. Future you will want to know.

How Do You Get Out of the Commit Message Editor?

When you run git commit without -m, Git opens a file that ends with this comment block:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.

Type your message above the comments, then save and close the editor. Git strips every line that starts with #. If nothing else is left, it stops and prints a message saying the commit was aborted because the message was empty.

The keys depend on which editor opened:

  • Vim (the usual default): press i to start typing. Then press Esc, type :wq and press Enter to save and commit. To bail out, type :q! to quit without saving, which leaves the message empty and aborts the commit.
  • Vim, during an amend: :q! won't abort here, because the old message is already in the file. Use :cq instead; Vim exits with an error code and Git cancels.
  • nano: press Ctrl+O then Enter to save, and Ctrl+X to exit.

If you'd rather never see Vim again, set the editor Git uses:

git config --global core.editor "nano"
git config --global core.editor "code --wait"

The --wait flag matters for VS Code. Without it the command returns at once, so Git reads the file before you've typed anything and a new commit aborts with an empty message. Git picks the editor from GIT_EDITOR, then core.editor, then VISUAL, then EDITOR, in that order.

GitHub Commit Message and GitLab Commit Message: What the Web UIs Do

Both platforms let you commit from the browser, and both store an ordinary Git message. On GitHub, editing a file and clicking "Commit changes..." gives you a "Commit message" field for the subject and a larger box below for an optional description. GitLab's web editor gives you a commit message box, so add the blank line between subject and body yourself.

Closing keywords work in commit messages on both. Per GitHub's docs on linking issues, keywords like close, fixes and resolved count in a commit message as well as a pull request description. GitLab has a similar closing pattern. On both platforms, the issue closes once the commit reaches the default branch, not when you push to a feature branch. A typical message looks like this:

Handle empty search queries

Fixes #214

For shared work on GitHub, add one Co-authored-by: Name <email> trailer per person at the end of the message. GitHub then lists each co-author on the commit.

One thing catches people out: neither GitHub nor GitLab renders Markdown in a commit view. The message appears as plain text, with issue references and URLs turned into links. **bold** shows up as literal asterisks. Keep Markdown for pull request and merge request descriptions, where it does render. Our GitHub Markdown cheat sheet and GitLab Markdown guide cover what works there.

How Do You See the Current Git Commit Message?

To read the message of the commit you're on, use git log or git show:

git log -1
git log --oneline -n 5
git show -s --format=%B HEAD
git log --format=%s

git log -1 prints the latest commit with its author, date and indented message. --oneline gives the short hash and subject for each commit. git show -s --format=%B HEAD prints only the raw message, with no diff and no indentation, which is handy in scripts. --format=%s lists subjects alone.

That last command shows why subjects matter. A history of clear imperative subjects reads like a list of shipped changes, ready to paste into release notes.

Commit Message Templates, Hooks and Release Notes

A template pre-fills the editor with prompts each time you run git commit. Create a file of # comments and point Git at it:

git config --global commit.template ~/.gitmessage
# Subject: imperative, about 50 chars, no period
#
# Body: why this change? What did you rule out?
#
# Fixes #

Lines starting with # are stripped, so the prompts never end up in the commit.

To enforce rules, add a commit-msg hook. Git runs .git/hooks/commit-msg with the path to the message file, and a non-zero exit aborts the commit. This one rejects subjects over 72 characters:

#!/bin/sh
subject=$(head -n 1 "$1")
if [ ${#subject} -gt 72 ]; then
  echo "Subject is ${#subject} chars; keep it to 72 or fewer." >&2
  exit 1
fi

Make it executable with chmod +x .git/hooks/commit-msg. Anyone can skip it with --no-verify, so treat it as a reminder, not a gate.

Some teams go further and adopt Conventional Commits, a spec that prefixes each subject with a type such as feat or fix so tools can work out version bumps. It's a layer on top of everything above, not a replacement. Our Conventional Commits cheat sheet lists the types and how they map to semantic versioning bumps.

Clean subjects pay off at release time. Paste your git log --oneline output into the changelog generator and it drafts Keep a Changelog or GitHub release notes text in your browser. It works from the text you paste; it doesn't connect to your repository.

A good git commit message takes thirty seconds to write and saves hours of archaeology later. Keep the subject short and imperative, leave a blank line, and use the body for the why. When it's time to ship, draft the release notes or PR description in the editor. You can check the Markdown preview there before you paste it into GitHub or GitLab.