Git Commit Messages With AI: Write Clear Commits Every Time
A step-by-step workflow for writing clear git commit messages with AI, from staging small changes to reviewing the draft against your diff and saving a reusable template.
- Time to complete
- 20 minutes to set up, then 2 minutes per commit
- Difficulty
- Beginner
- Tools needed
- Gita terminalany AI chat assistant or AI coding tool (ChatGPT, Claude, Gemini or GitHub Copilot)a code editor such as VS Code
A good git commit message tells the next person, often you in six months, what changed and why, in a few lines they can scan in git log. AI is very good at drafting that message from your staged diff, as long as you give it small, focused changes and check its draft before you commit.
Most messages still end up as "fix" or "wip", because by the time the code works you just want to move on. This workflow removes that friction. You stage a small change, hand the diff to an AI assistant with a solid prompt, review the result against the code, and commit. Then you save the prompt and a template so it takes two minutes every time, with any editor, language or assistant.
What You'll Need
- Git and a repository to practise on. A personal project is fine.
- A terminal. Git Bash on Windows, Terminal on macOS or any Linux shell.
- An AI assistant. ChatGPT, Claude, Gemini or a coding tool such as GitHub Copilot. Free tiers are enough, because the inputs are small.
- Your team's rules, if any. Some teams use Conventional Commits, some require ticket numbers.
- Your company's AI policy. This is not optional. More on it in Step 2.
Step 1: Stage Small, Logical Changes
The quality of an AI-drafted message depends on what you give it. If you stage a bug fix, a new feature and some formatting together, no model can write one honest message, because it is really three commits.
A useful test: can you describe the change in one sentence without the word "and"? If not, split it. Interactive patch mode lets you stage parts of a file.
git status # see what has changed
git add -p src/payments/transfer.ts # stage only the relevant hunks
git diff --staged --stat # check what is staged
If your changes are tangled, AI can help you plan the split.
Here is the output of git status and git diff for my [LANGUAGE/FRAMEWORK] project:
[PASTE OUTPUT]
Suggest how to split these changes into separate, logical commits. For each commit, list the files or hunks it should include and a one-line description. Do not write commit messages yet.
Checkpoint: Your staged changes do one thing, and you can describe it in a single sentence.
Step 2: Get the Staged Diff (and Clean It)
The AI needs to see exactly what you are about to commit, which is the staged diff, not your whole working tree.
git diff --staged # show the next commit
git diff --staged | pbcopy # copy it on macOS
git diff --staged | clip # copy it in Git Bash on Windows
Before you paste anything into a chatbot, read the diff. This is the security step people skip.
- Never paste secrets. API keys, database passwords, Paystack secret keys and tokens from
.envfiles should not be in a diff at all. If you find one, remove it from the commit and rotate the key. - Check your company's policy. Many employers do not allow proprietary code in consumer chatbots, and some provide an approved tool under a business licence. Use that one.
- Trim noise. Lock files and generated code add length without helping. Leave them out and simply mention that they changed.
Checkpoint: You have the staged diff, it contains no secrets, and you are allowed to share it with your chosen tool.
Step 3: Prompt AI to Draft a Conventional Commits Message
Conventional Commits is a widely used format that makes history easy to scan and lets tools build changelogs. The shape is type(scope): summary, then a blank line, a body explaining why, and optional footers for breaking changes or issue references. Common types are feat, fix, docs, refactor, test, perf, build, ci and chore. A breaking change is marked with ! after the type or scope, or a BREAKING CHANGE: footer.
The AI can see what changed, but not why. Only you know that, so give it a sentence or two of context.
Write a git commit message for the staged diff below.
Rules:
- Conventional Commits: type(scope): summary
- Summary in the imperative ("add", not "added"), ideally 50 characters, 72 maximum, no full stop
- Blank line, then a body wrapped at 72 characters explaining WHY the change was made and any side effects. Do not just list files.
- Footers only if they apply: "BREAKING CHANGE: ..." and "Closes #[ISSUE-NUMBER]" or "Refs: [TICKET-ID]"
- Do not invent anything that is not in the diff or my context. If something is unclear, ask me.
Why I made this change: [ONE OR TWO SENTENCES]
Ticket or issue: [ID OR "none"]
Team conventions: [e.g. "scope is the folder name", or "none"]
Staged diff:
[PASTE DIFF]
Give one recommended message and one shorter alternative.
Checkpoint: You have a draft with a typed summary line, a body that explains the reason, and footers only where they belong.
Step 4: Review the Draft Against the Diff
Fluency hides mistakes. Typical errors include claiming a change "improves performance" when nothing was measured, describing a file that was not staged, or choosing feat for what is really a fix. Read the draft with the diff beside it and check four things:
- Is every claim true? Each sentence should match the diff or your context.
- Is the type right? A user-visible bug fix is
fix; renaming variables isrefactor. - Is it breaking? A changed function signature, API response or database column needs
!and a footer. AI often misses this. - Is the "why" real? Replace vague lines like "to improve code quality" with your actual reason.
You can also ask the AI to check itself.
Compare this commit message to the diff. List any statement not supported by the diff, any change the message misses, and whether the type and breaking-change marker are correct. Be strict.
Message:
[PASTE DRAFT]
Diff:
[PASTE DIFF]
For a fuller check of the code itself, our workflow on AI code review before you push pairs well with this step.
Checkpoint: Every line is accurate, the type is correct, and any breaking change is flagged.
Step 5: Commit and Check the Result
For a message with a body, run git commit with no flags so your editor opens and the formatting survives, or pass one -m per paragraph.
git commit # paste the message in your editor
git log --oneline -5 # check how it reads in history
git commit --amend # fix the last message, only if NOT pushed
Never amend pushed commits: rewriting shared history hurts everyone on the branch.
Checkpoint: The commit appears in git log --oneline with a summary line that makes sense on its own.
Step 6: Make It Reusable With a Template and Alias
Save the work once so you never start from scratch. First, a commit template that Git loads into your editor every time you commit:
cat > ~/.gitmessage << 'EOF'
# type(scope): summary (imperative, 50 to 72 chars)
# Why was this change needed? What does it affect?
# Closes #NUMBER | Refs: TICKET-ID | BREAKING CHANGE: ...
EOF
git config --global commit.template ~/.gitmessage # use for every commit
git commit -t ~/.gitmessage # or just once
Lines starting with # are stripped from the final message. Second, an alias that copies your staged diff in one command (swap pbcopy for clip on Windows):
git config --global alias.aidiff '!git diff --staged | pbcopy && echo "Diff copied"'
git aidiff
Third, keep the Step 3 prompt somewhere you can reach in seconds, such as a text expander snippet or a saved prompt in your AI tool. If you use a coding agent that reads a project instructions file, put your commit rules there. Our guide on how to write AGENTS.md for coding agents shows how to add a short "Commit messages" section.
Checkpoint: You can go from staged changes to a reviewed message in about two minutes.
Step 7: Use AI in Your Editor and Agree Team Conventions
Many editors now draft commit messages without any copying. In VS Code with GitHub Copilot, the Source Control panel has a button beside the commit message box that generates a message from your staged changes; the icon changes between versions, so look for the AI symbol next to the field. Microsoft also announced that its new MAI Code 2 models are coming to GitHub Copilot, covered in our Microsoft Ignite 2026 MAI models report. Terminal-based coding agents can often stage and commit by themselves. If you are new to them, start with our explainer on what an AI agent is, then our guide on how to choose an AI coding agent.
Editor buttons rarely know your reason or ticket number, so treat their output as a first draft and apply the Step 4 review. For teams, write the rules down: allowed types and what they mean, how scopes are named, whether ticket references are required, and which AI tools are approved for which repositories.
The same approach works for pull request descriptions.
Write a pull request description from these commits.
Commits:
[PASTE git log --oneline main..HEAD]
What this PR does and why: [TWO OR THREE SENTENCES]
Format: a summary paragraph, a "Changes" list, a "How to test" list and a "Risks" list. Do not invent tests I have not described.
Checkpoint: Your team has written conventions, and every AI draft still gets a human review.
Good vs Bad Commit Messages
| Bad message | Why it fails | Better message |
|---|---|---|
| fix | Says nothing about what or where | fix(auth): stop OTP expiring before SMS arrives |
| updated stuff | Past tense, vague, no scope | refactor(cart): extract price calculation into helper |
| WIP | Not meant to be read by anyone | feat(profile): add photo upload with size check |
| fixed bug from yesterday | Relies on memory nobody else has | fix(transfer): round naira amounts to two decimals |
| changed API | Hides a breaking change | feat(api)!: return amounts in kobo instead of naira |
A good summary line names the type, the area and the change in plain words. The body carries the detail.
Worked Example: Ifeoma, a Junior Developer in Lagos
Ifeoma, an invented example, is six months into her first job as a junior backend developer at a fintech start-up in Yaba, Lagos. Her team lead wants everyone on Conventional Commits because the main repository's history has become hard to read.
On Tuesday she fixes a bug that let customers exceed their daily transfer limit by sending two payments from two browser tabs at once. While in the code, she also renames some confusing variables. Her first instinct is to commit everything as "fix transfer bug".
Instead she follows the workflow. She uses git add -p to stage only the limit check and its test, then reads the staged diff. She spots a sandbox secret key someone left in a test file months ago, removes it, and tells her lead, who rotates it. Her company provides an approved AI assistant under a business plan, so she uses that rather than her personal account.
Her context line reads: "Two simultaneous transfers could both pass the limit check because we read the daily total before locking the account row." The AI drafts:
fix(transfer): enforce daily limit under concurrent requests
Lock the account row before reading today's total so two
simultaneous transfers cannot both pass the limit check.
Adds a test that fires two transfers in parallel.
Closes #318
The self-check prompt flags that the test does not run the transfers in parallel; it uses a mocked delay. She corrects that line. Then she commits the variable renames separately as refactor(transfer): rename limit variables for clarity.
Both commits take about six minutes, including the secret-key scare, and her lead later points to them as the model for the team.
Common Mistakes
- Committing too much at once. A diff covering three ideas produces a vague or wrong message. Split first.
- Pasting secrets or work code into a consumer chatbot. Read the diff first and use the tools your employer approves.
- Skipping the "why". AI can describe what changed but not your reason. One sentence of context fixes this.
- Trusting the draft unread. Watch especially for invented performance claims and missed breaking changes.
- Letting an agent commit unsupervised. Review agent commits the same way. Our vibe coding workflow shows how to keep agent work in small, checkable steps.
FAQ
What is a good git commit message?
A good git commit message has a short imperative summary line, such as "fix(login): handle expired session", then a blank line and a body explaining why the change was made. It covers one logical change, reads clearly in git log --oneline, and includes issue references or breaking-change notes when they apply.
Is it safe to paste my code into a chatbot to write commit messages?
It depends on the code and your employer. Never paste secrets such as API keys or passwords. For work code, check your company's AI policy first, because many organisations only allow approved tools with business data protections.
Do I have to use Conventional Commits?
No. It is a popular convention, not a Git rule. If your team has its own format, put those rules in your prompt instead. It is a sensible default because many changelog tools understand it.
Can AI write the commit message automatically?
Yes. Several editors and coding agents, including GitHub Copilot in VS Code, can draft a message from your staged changes, and some agents commit by themselves. The draft still needs your review, because the tool does not know your reason or ticket number unless you tell it.
How long should a commit message be?
Aim for a summary line of about 50 characters and no more than 72. The body, wrapped at 72 characters, is usually two to five lines. If you need many paragraphs, the commit may be doing too much, or the detail may belong in the pull request.
Start This Week
Pick one repository and use this workflow for every commit for five working days. Set up the template and alias on day one, save the prompt, and review each draft against the diff. By Friday it will feel automatic.
If you want better code going into those commits, start earlier with our workflow on planning before you code with AI. Clear plans lead to small, focused changes, and small, focused changes make commit messages almost write themselves.
More in Coding Workflows.


