Git history is documentation. Bad commit messages and shapeless pull requests slow your team down for years. AI can take the friction out of writing both — but only if you feed it the actual diff and your team's conventions.
Most developers write commit messages and PR descriptions reluctantly, at the end of a long day, in two lines they will regret reading later. AI removes the cost of doing it properly: paste the diff, get a clear, conventional commit and a structured PR description in seconds. This tutorial walks through the patterns that work and the patterns that don't.
The only reliable input for AI when writing about a change is the change itself — the diff. Without it, the AI invents what you might have done. With it, the AI summarises what you actually did.
Think of the diff as the evidence and the AI as the writer. A good writer with the wrong evidence produces fiction; the same writer with the right evidence produces useful documentation.
The classic mistake is asking for a commit message without showing the change.
Weak prompt
write a commit message for my changes to the order endpoint
The AI will produce something generic like fix: update order endpoint — accurate in zero useful ways. Six months later, no one reading git log learns anything from this commit.
Strong prompt
Our team follows Conventional Commits. Allowed types:
feat, fix, refactor, docs, test, chore, perf, style.
Scope is the affected module (e.g. orders, auth, ui).
Subject line ≤ 72 chars, imperative mood, no trailing period.
Body: explain the WHY in 1–3 short bullets when non-trivial.
Here is the staged diff:
```diff
diff --git a/src/routes/orders.ts b/src/routes/orders.ts
@@
- if (req.body.quantity > 99) {
- return res.status(400).json({ error: 'too many' });
- }
+ const result = orderBodySchema.safeParse(req.body);
+ if (!result.success) {
+ return res.status(400).json({
+ error: { code: 'INVALID_BODY', message: result.error.message }
+ });
+ }
```
Write:
1. A commit message in our format.
2. A suggested branch name (kebab-case, prefixed with feat/, fix/, or
refactor/ as appropriate).
3. A PR description with sections: Summary, Why, How, Test plan.
The AI now has the convention, the actual diff, and the three artefacts to produce. The output will be specific to this change and consistent with how the rest of the repo looks.
git diff --staged for commit messages, git diff main...HEAD for PR descriptions.Tip: For long-running PRs, regenerate the description from the cumulative diff before requesting review. It keeps the summary in sync with what the code actually became, not what it was two days ago.
Open one of your last five PRs. Run git diff main...HEAD and feed it to the AI with your team's conventions. Compare the AI's suggested message and PR description to what you actually wrote. Which one would your reviewer have preferred?
Write a small change in your project (a bug fix, a refactor). Before committing, paste the diff and ask the AI for three commit message options — one terse, one normal, one detailed. Pick the one that fits the change best. Notice how granularity matters.
Set up a one-line Git alias that pipes the staged diff into your preferred AI tool with your team's commit-convention prompt. Time how long it takes to commit a small change before and after this setup.
Sign in to join the discussion and post comments.
Sign inPrompt Engineering Projects & Real-World Applications
Twelve hands-on projects that turn prompt engineering theory into a portfolio. Build chatbots, content generators, RAG systems, and more.
Prompt Engineering for Data Science & Analytics
Supercharge your data workflows with AI. 15 practical tutorials on using prompt engineering for data cleaning, EDA, machine learning, SQL, visualisation, and more.
Prompt Engineering for Specific AI Tools
Tool-by-tool mastery — deep dives into ChatGPT, Claude, Gemini, GitHub Copilot, Midjourney, Stable Diffusion, and more. Learn the exact prompting techniques each platform rewards.
Prompt Engineering for Business & Productivity
Use AI to work smarter — automate tasks, make better decisions, and communicate professionally. 12 practical business prompt tutorials for professionals.
Prompt Engineering for Education & Learning
Use AI as your personal tutor. Learn how to study faster, create lesson plans, generate practice questions, master languages, and prepare for competitive exams with smart prompts.
Prompt Engineering for Content & Copywriting
Write blogs, ads, emails, and social media content ten times faster with AI. 13 practical tutorials on prompt engineering for content creators and copywriters.