cd /news/developer-tools/how-to-write-better-git-commit-messa… Β· home β€Ί topics β€Ί developer-tools β€Ί article
[ARTICLE Β· art-27756] src=dev.to β†— pub= topic=developer-tools verified=true sentiment=↑ positive

How to Write Better Git Commit Messages with AI

A developer has created an AI-powered workflow to generate better Git commit messages using tools like ChatGPT, Claude, or Copilot Chat. The method involves feeding a staged diff and intent into a prompt that outputs a Conventional Commits-formatted message, reducing the time to 30 seconds. The developer also recommends automating the diff copy with a shell alias and enforcing format compliance with commitlint.

read4 min publishedJun 15, 2026

Bad commit messages are a tax you pay forever. You hit git log

six months later and find a wall of "fix stuff", "WIP", "asdf", and "final final v2" β€” and now you're archaeologist instead of engineer. The good news: AI can eliminate this problem almost entirely, and in this walkthrough I'll show you exactly how to wire it into your workflow with copy-paste prompts you can use today.

The root cause isn't laziness β€” it's timing. You write the commit message right after a long coding session, when your brain is fried and you just want to push. Context is all in your head, not on the screen.

AI flips this. You feed it the diff and your rough notes; it drafts a structured message. You edit for accuracy. Total time: 30 seconds. The output is consistently better than what most engineers write under pressure.

Before prompting, get a clean diff of what you're about to commit:

git diff --staged

Copy the output. If the diff is large (500+ lines), narrow it to the most meaningful files:

git diff --staged -- path/to/relevant/file.ts

You don't need to paste every line into the prompt β€” a representative slice plus a plain-English summary of your intent is enough.

Paste this into your AI assistant of choice (ChatGPT, Claude, Copilot Chat, etc.):

You are a senior engineer helping me write a Git commit message.

Here is the staged diff:
<paste diff here>

My intent: <one sentence about what this change accomplishes and why>

Write a commit message using the Conventional Commits format:
- First line: type(scope): short imperative summary (max 72 chars)
- Blank line
- Body: 2–4 bullet points explaining WHAT changed and WHY, not HOW
- If there's a breaking change, add a BREAKING CHANGE footer

Output only the commit message, no commentary.

A real example output for a token-refresh bug fix might look like this:

fix(auth): prevent silent token refresh on expired session

- Remove automatic refresh call when session TTL has already elapsed
- Add explicit expiry check before calling refreshToken()
- Prevents a race condition that caused duplicate refresh requests
  under slow network conditions

That's immediately useful to the next engineer reading git log

.

If the first draft is close but not quite right, don't re-explain from scratch. Just correct the specific problem:

The scope should be "session" not "auth", and the first line
is too long β€” tighten it to under 60 characters.

AI handles surgical edits like this well. You're the reviewer; it's the first-draft writer.

The friction of copy-pasting manually will kill this habit. Automate it. Add this to your .zshrc

or .bashrc

:

alias gcm='git diff --staged | pbcopy && echo "Diff copied. Paste into your AI prompt."'

On Linux, swap pbcopy

for xclip -selection clipboard

. Now your staged diff is on your clipboard in one command, ready to paste into any AI chat.

For teams using the GitHub CLI, you can go further and pipe directly into a script that calls an API β€” but the manual copy-paste habit alone will get you 80% of the value.

Writing good messages is only half the battle β€” the other half is making sure they don't regress. Add commitlint

to your repo:

npm install --save-dev @commitlint/cli @commitlint/config-conventional
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'

Now any commit that doesn't follow Conventional Commits format gets rejected before it ever touches your branch. Pair this with the AI prompt above and the format issues go away almost entirely.

This prompt pattern is one of the ones I've packaged into The AI Leverage Playbook: 50 Prompts & Workflows for Engineers β€” but the version above is enough to get real value on its own.

Once this habit is set, your git log

becomes actual documentation. You can:

git log --oneline

to get a readable changelog for a releasegit log --grep="fix(auth)"

to find every auth-related fix without grepping sourceThe commit message becomes a first-class artifact, not an afterthought.

You are a senior engineer helping me write a Git commit message.

Diff:
<paste>

Intent: <one sentence>

Format: Conventional Commits. First line ≀72 chars, imperative mood.
Body: 2–4 bullets on what changed and why. BREAKING CHANGE footer if needed.
Output the commit message only.

Save that. Reach for it every time you're about to type "fix stuff."

I break down one workflow like this every week in The AI Leverage Weekly β€” practical, no fluff, free. Subscribe: https://theaileverageweekly.beehiiv.com/subscribe?utm_source=devto&utm_medium=article&utm_campaign=long_w6

── more in #developer-tools 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/how-to-write-better-…] indexed:0 read:4min 2026-06-15 Β· β€”