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 for Image Generation
Turn words into stunning visuals. Master AI image generation tools like Midjourney, DALL·E 3, and Stable Diffusion with 18 focused tutorials — from first prompt to full brand identity.
Advanced Prompt Engineering Techniques
Master the powerful techniques AI experts use every day. Chain-of-thought, RAG, agents, function calling, prompt evaluation, and much more — 20 deep-dive tutorials.
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 Business & Productivity
Use AI to work smarter — automate tasks, make better decisions, and communicate professionally. 12 practical business prompt tutorials for professionals.
Foundations of Prompt Engineering
The must-know basics of prompt engineering. Learn what prompts are, how AI models read them, and how to write clear instructions that get great results.
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.