·

Git And PR Workflows With AI

Git And PR Workflows With AI

The most-read documentation in your codebase is your git history — AI can make every commit message and PR description actually worth reading.

Why Git Hygiene Is an Engineering Multiplier

Engineers spend enormous energy writing code and almost no energy describing it. The result is a git history full of "fix bug", "WIP", and "update stuff" — a record that tells the story of keystrokes, not intent. This matters more than it seems. Git history is how your team debugs regressions three months from now, how new engineers understand what changed and why, and how you write changelogs without reconstructing context from memory.

AI changes the economics of this. Writing a good commit message used to take deliberate effort — you had to stop, think about what you actually changed, and write something coherent. AI can draft that message in two seconds from your diff. The barrier to good git hygiene drops to almost zero. What remains is the habit of using it, and the discipline to review and refine what AI generates before committing.

This section covers the full git communication workflow with AI: commit messages in Conventional Commits format, PR descriptions that communicate intent to reviewers, changelog generation from commit history, and how to automate this with git hooks.

Learning tip: Your future self will thank you for every commit message you write well. AI removes the friction — but you still need to read and correct the output before it becomes permanent.


Generating Commit Messages with AI

The gold standard for commit messages is the Conventional Commits specification: a structured format that makes messages machine-readable for changelog generation and human-readable for code archaeology. The format is type(scope): description, where type is one of feat, fix, refactor, perf, test, docs, chore, build, or ci.

The most effective workflow is: stage your changes, generate a diff, and feed that diff to AI with a clear instruction. Never give AI a vague prompt like "write a commit message for my changes." Give it the diff — the actual lines that changed — and specify the format you want.

One common mistake: accepting the first AI-generated message without reading it. AI sometimes gets the type wrong (calling a refactor a fix), misses the scope, or describes the mechanism rather than the intent. Always read the output and adjust the description to capture the "why," not just the "what."

Here is a git diff of my staged changes:

[paste output of: git diff --staged]


Write a commit message in Conventional Commits format. Rules:
- Format: type(scope): short description (max 72 characters)
- Types: feat, fix, refactor, perf, test, docs, chore, build, ci
- The scope should be the module, file, or feature area affected
- The short description should describe what changed in imperative mood ("add", "remove", "update" — not "added", "removed", "updated")
- If the change is non-trivial, add a body (separated by blank line) that explains WHY the change was made, not what changed (the diff shows what changed)
- If there are breaking changes, add a footer: BREAKING CHANGE: [description]

Output only the commit message. No explanation.

For a more nuanced commit involving multiple logical changes, add this to your prompt:

The diff above contains two separate logical changes. Please write a commit message for the primary change only: [describe which change]. Note that the secondary change ([describe it]) will be committed separately.

Learning tip: If your diff spans more than one logical change, split your commits before generating the message. AI will generate a better message for a focused diff, and your history will be more navigable.


Writing PR Descriptions That Actually Help Reviewers

A good PR description answers three questions every reviewer asks before reading a line of code: What did you change? Why did you change it? How do I verify it works? Most PR descriptions answer none of these. They repeat the ticket title, say "see linked issue," and leave the reviewer to reconstruct context from the diff.

AI can generate a strong first draft of a PR description if you give it the right inputs: the diff or a summary of changes, the original requirement or ticket, and any testing context. The output needs human review and adjustment — AI won't know about the edge case you decided not to handle, or the approach you considered and rejected — but it eliminates the blank-page problem.

The most useful PR descriptions include: a one-sentence summary (the "elevator pitch"), a bulleted list of changes, a "why" section explaining the motivation, a testing section describing how to verify behavior, and a "decisions and tradeoffs" section if any non-obvious choices were made. AI can draft all of these; you add the human context.

I'm writing a pull request description for the following change.

**Ticket / requirement summary:**
[Describe what was asked for, 2–4 sentences]

**Summary of changes made:**
[Paste git log --oneline for this branch, or list the main changes]

**Key technical decisions made:**
[Describe any non-obvious choices, e.g. "I chose approach X over Y because..."]

**Testing performed:**
[Describe how you tested it]

Generate a PR description in this format:

## Summary
[1–2 sentence description of what this PR does and why]

## Changes
[Bulleted list of the main changes, grouped by area if needed]

## Motivation
[Why this change was needed — the problem it solves or the requirement it fulfills]

## Testing
[How to verify the changes work correctly, including test cases to run manually if applicable]

## Decisions and Tradeoffs
[Only include if there were non-obvious choices. Describe what was considered and why this approach was chosen.]

## Checklist
- [ ] Tests added or updated
- [ ] Documentation updated if needed
- [ ] No secrets or credentials in the diff

Learning tip: The "Decisions and Tradeoffs" section is the most valuable part of a PR description and the part engineers skip most. AI will draft it from what you give it — but you have to actually tell it what you decided and why.


Changelog Generation from Commit History

Changelogs suffer from the same problem as commit messages, amplified: they're written under time pressure, long after the code shipped, by an engineer who has to reconstruct what changed across dozens of commits. The result is incomplete, inaccurate, or nonexistent.

AI makes changelog generation practical if your commit history is good. This is the compounding return on writing good Conventional Commits messages: when changelog time comes, you feed the history to AI and get a structured, categorized output in minutes.

The process:
1. Get the commit log for the release range: git log v1.2.0..v1.3.0 --oneline
2. If you need more detail: git log v1.2.0..v1.3.0 --pretty=format:"%h %s%n%b"
3. Feed it to AI with a changelog prompt

Here is the git commit history for the release from v[previous] to v[current]:

[paste git log output here]


Generate a changelog entry for this release in Keep a Changelog format (https://keepachangelog.com). Rules:
- Group changes under: Added, Changed, Deprecated, Removed, Fixed, Security
- Only include user-facing or API-level changes under Added, Changed, Fixed, Removed
- Internal refactors and test changes go under a "Internal" section (or omit them if not relevant for users)
- Each line should be written for a technical audience (developers using or maintaining this software)
- Keep each line to one sentence. Start with a verb in past tense ("Added", "Fixed", "Removed")
- If a commit message is ambiguous, flag it with [NEEDS REVIEW] rather than guessing

Output the changelog section only, formatted in Markdown.

Learning tip: Changelog generation quality is directly proportional to commit message quality. If your commits are "fix stuff" and "update things," no AI can produce a useful changelog. Invest in commit messages and changelog generation becomes nearly free.


Automating PR Workflows with Claude Code and Git Hooks

The highest-leverage integration point for AI in git workflows is automation at the commit and push stage. Rather than manually copying diffs into a chat window, you can wire AI into your git workflow so it runs automatically.

Commit message hook (prepare-commit-msg): This git hook runs before your editor opens for the commit message. You can use it to pre-populate a draft message from AI based on the staged diff. The engineer reviews and edits before confirming.

A simple shell hook that calls Claude Code CLI to generate a draft:


Given the following staged diff, generate a Conventional Commits message.
Output only the commit message (subject line + optional body). Nothing else.

[staged diff appended here by the hook script]

PR description template with AI fill-in: Many teams use GitHub PR templates (.github/pull_request_template.md). Add structured sections that prompt AI to fill in: include comment placeholders that describe what should go in each section. When you run your AI tool against the PR, it knows exactly what to fill in and where.

Branch naming convention check (pre-push hook): Use a pre-push hook to validate that branch names follow your convention (feature/, fix/, chore/). If the name doesn't match, pause and ask AI to suggest a compliant name based on the commits on the branch.

Learning tip: Start with one hook — the prepare-commit-msg hook for AI-generated commit messages. Get comfortable with it for two weeks before adding more automation. The goal is to reduce friction, not add new failure modes to your git workflow.


Making PRs Self-Documenting for Reviewers

A self-documenting PR is one where a reviewer with zero prior context can understand: what the change is, why it was made, what was considered and rejected, and how to verify it. This is the goal every PR should aim for, and AI can help you get there consistently.

The checklist for a self-documenting PR:

  1. Atomic commits with good messages: each commit tells one story. Use AI to generate and refine commit messages before pushing.
  2. PR description that answers: what, why, how to verify: generated from AI with your context inputs, reviewed and enriched by you.
  3. Inline comments for non-obvious code: add comments in the PR diff for any section where the "why" isn't obvious from reading the code. AI can draft these too.
  4. Test coverage visible in the PR: tests should be part of the same PR, not a follow-up. The reviewer should be able to run the tests to verify behavior.
  5. Changelog entry drafted: if your project has a changelog, include a draft in the PR. Reviewers can verify it's accurate.
I'm adding inline comments to my PR to explain non-obvious implementation choices. Here is a section of code that a reviewer might not immediately understand:

[paste the code section]


Context: This code [describe what it does and why it's structured this way — mention any alternatives you considered and rejected].

Write a concise inline comment (2–4 sentences) that explains the "why" behind this implementation to a reviewer who is seeing it for the first time. Do not describe what the code does (the reviewer can read the code). Explain the reasoning, constraints, or tradeoffs that led to this approach.

Learning tip: The test for a self-documenting PR is: could a senior engineer on your team understand this change and its motivation without asking you any questions? Run that test mentally before marking a PR ready for review.


Key Takeaways

  • Use AI to generate Conventional Commits messages from staged diffs. Always provide the actual diff — not a verbal description — and review the output before committing.
  • PR descriptions should answer: what changed, why, and how to verify. Provide AI with the ticket summary, list of changes, technical decisions, and testing context to get a useful first draft.
  • Changelog generation is nearly free if your commit history follows Conventional Commits format. Feed the commit log range to AI with a structured changelog prompt.
  • Automate AI into your git workflow with prepare-commit-msg hooks for commit message drafts. Start with one hook; add more only after the first is stable.
  • A self-documenting PR makes reviewers faster and your codebase more navigable. AI reduces the effort required to reach that standard — use it as a forcing function for better git hygiene.