Best ChatGPT Prompt for Git Commit Messages
Paste the diff, get a commit message in the convention your team actually uses.
The Prompt
You are a senior engineer who has reviewed thousands of pull requests. Write a Git commit message for this change. Convention to follow: [Conventional Commits / Angular / team-custom / just plain English] Repo context (one sentence): [WHAT THE PROJECT IS, e.g. “a Next.js marketing site”] The diff: ``` [PASTE git diff OR PATCH HERE] ``` What I was actually trying to do (in my own words): [ONE OR TWO SENTENCES] Related ticket / issue (if any): [ID or URL] Requirements: - Subject line: imperative mood, under 72 characters, no trailing period - If using Conventional Commits, pick the right type (feat / fix / refactor / docs / chore / test / perf / build / ci / style) - Body (if needed): explain WHY, not WHAT — the diff already shows what changed - If the change is split across concerns (e.g. a refactor + a bug fix), call that out and suggest splitting the commit - If the diff and my description disagree, ASK before writing — don't paper over a mismatch
How to Use This Prompt
- Run
git diff --staged(orgit diff HEAD~1) and paste the output - Tell the model the convention — Conventional Commits is the most common but say what your team uses
- Describe what you were trying to do in plain English — the diff alone doesn't tell the model the why
- Paste into ChatGPT or Claude
- Review the message before committing — the model can mis-read intent if the diff is large
If the diff is over ~300 lines, the commit probably should be split. A good prompt response will tell you that instead of writing one giant message.
Example Output
Task: Commit message for a fix that adds null-check to a user lookup
Response:
fix(auth): handle null user in session lookup The session lookup was crashing when a user was deleted mid-session because we assumed `users.findById` always returned an object. It can return null when the row is gone. Caller now handles the null case and clears the session instead. Refs #4821
Tips to Get Better Results
- Stage first, then diff.
git diff --stagedgives the model exactly what's going into the commit.git diffshows unstaged work too. - Don't paste 1,000-line diffs. If the diff is huge, the commit should be split. Ask the model “should this be one commit or multiple?”
- The WHY is the whole point. “Updated user.ts” is useless. “Handle null user in session lookup because deleted users were crashing the session middleware” tells the next reader (or future you) what they need.
- Iterate on tone. If your team writes terse commits, say “keep it to one line, no body.” If your team writes essays, say so.