Chapter 8

AI + Git Workflow

Version control is central to modern development. With AI, you can improve nearly every step of the Git workflow — from writing clear commits to reviewing pull requests to resolving merge conflicts.


The Problem with Most Git History

Let's be honest: most developers write terrible commit messages. Under deadline pressure, tired at the end of a session, or just not caring enough, the history fills up with messages like these:

fix stuff
update code
misc changes
wip
asdfasdf

This makes the project history useless. Six months later, nobody — including you — can understand what changed, why, or when a bug was introduced. AI eliminates this problem by generating clear, descriptive commit messages from your actual code changes.


Commit Messages with AI

The simplest and highest-impact use of AI in your Git workflow is generating commit messages. Give AI your diff and it produces a precise, professional message every time.

Here is my git diff:

[paste output of `git diff --staged`]

Write a commit message following conventional commits format.
Be specific about what changed and why.
Keep the subject line under 72 characters.

A good AI-generated commit message looks like:

feat(schedule): add CRUD functionality for activities
Adds create, read, update, delete operations for the activity model with form validation and optimistic UI updates.
fix(filter): resolve incorrect member matching in FilterBar
Fixes case-sensitive comparison that caused filter to miss activities when member names had different casing.
refactor(hooks): extract activity state into useSchedule hook
Moves activity CRUD logic from App component into dedicated custom hook, improving separation of concerns.

Each message immediately tells you what type of change it is, where in the codebase it happened, and what specifically changed. This is the difference between a project history you can actually use and one that's just noise.


Conventional Commits

The conventional commits format is a widely adopted standard that makes Git history machine-readable and human-scannable. AI follows this format naturally when you ask for it. Here are the most common prefixes:

feat New feature or capability added fix Bug fix that corrects incorrect behavior refactor Code improvement that doesn't change behavior docs Documentation changes only style Visual/CSS changes, formatting, whitespace test Adding or fixing tests chore Build process, dependencies, configuration

The format is: type(scope): description. The scope is optional but helpful — it tells you which part of the codebase was affected. AI is remarkably good at choosing the right type and scope when given the diff.

Pro Tip: Automate It

Many developers create a shell alias or Git hook that automatically sends the staged diff to AI and returns a commit message. This way, writing good commits takes zero extra effort. Tools like aicommits and similar CLI tools do exactly this. Even without automation, building the habit of pasting your diff before committing takes only seconds and dramatically improves your project history.


Branch Strategy

AI can help you design and maintain a branching strategy that keeps your repository organized. This matters most as projects grow and teams expand.

Suggest a Git branch strategy for this project.

Context:
- Solo developer now, team of 2-3 in 6 months
- Web app with React frontend and Node backend
- Deployed to production continuously
- Need to work on features without breaking main

Keep it simple — I can add complexity later.

A solid starting strategy:

main
Production-ready code. Always deployable.
develop
Integration branch. Features merge here first.
feature/add-filters
One branch per feature. Branch from develop.
feature/edit-modal
Work in isolation. Merge back to develop.
fix/filter-case-bug
Bug fixes. Can branch from main for hotfixes.

For solo developers, even just main + feature/* branches is a huge improvement over committing everything directly to main. The discipline of working in feature branches means you always have a clean, deployable main branch.


Pull Request Reviews

AI is an excellent first-pass code reviewer. Before asking a human colleague to review your PR (or before merging solo work), run it past AI. It catches issues that are easy to miss when you're close to the code.

Review this pull request as a senior developer.

Here is the diff:
[paste the full diff or key files]

This PR adds: [brief description of what the PR does]

Review for:
- Correctness (bugs, edge cases, off-by-one errors)
- Code quality (naming, structure, duplication)
- Performance (unnecessary re-renders, N+1 patterns)
- Security (input validation, data exposure)
- Missing tests

Be specific — point to exact lines and explain the issue.

AI catches things that human reviewers often miss — especially repetitive issues like inconsistent naming, missing null checks, or performance anti-patterns that are easy to overlook file by file.

PR Review Checklist

You can also ask AI to generate a review checklist specific to your project. Here's a universal starting point:

Does the code do what the PR description says? — Verify the implementation matches the stated goal.
Are there any obvious bugs or edge cases? — Null values, empty arrays, boundary conditions.
Is naming clear and consistent? — Can you understand what each function and variable does?
Is there duplicated logic? — Any code that appears twice should be extracted.
Are types correct and complete? — No any types, proper interfaces, strict null checks.
Is error handling sufficient? — What happens when things fail?
Are there performance concerns? — Unnecessary renders, missing memoization, heavy computations in render path.
Is the commit history clean? — Logical, focused commits with descriptive messages.

Merge Conflict Resolution

Merge conflicts are one of the most stressful parts of Git — especially in unfamiliar code. AI can analyze both sides of a conflict and suggest the best resolution, often understanding the intent of each change.

I have a merge conflict. Here are both versions:

<<<<<<< HEAD (my branch)
const filtered = activities.filter(a =>
  selectedMembers.includes(a.member)
);
=======
const filtered = activities.filter(a =>
  a.member === activeMember && a.day === selectedDay
);
>>>>>>> develop

My branch adds: multi-select member filtering
Develop branch adds: day-based filtering

How should I merge these? I need both filters to work together.

By explaining the intent of each branch, you give AI the context to combine them correctly — not just concatenate the code, but actually merge the logic so both filters apply simultaneously.

Key Insight

Always explain the intent behind each branch's changes. Git conflicts are syntactic — they show you two versions of the same code. But resolving them correctly requires understanding what each version was trying to do. AI can't infer this from the code alone.


Changelog and Release Notes

When it's time to ship a release, AI can transform your commit history into human-readable changelogs and release notes — if your commits follow a consistent format.

Here are the commits since the last release:

feat(schedule): add weekly view with day columns
feat(filter): add multi-select member filtering
fix(modal): prevent form submission with empty name
refactor(hooks): extract useSchedule from App
style(calendar): improve mobile responsive layout
docs(readme): add setup instructions

Generate:
1. A CHANGELOG.md entry grouped by type
2. User-facing release notes (non-technical)

This produces two outputs: a technical changelog for developers (grouped by feat/fix/refactor) and a user-facing summary ("You can now filter activities by family member, and the calendar looks better on phones"). The quality of both depends entirely on the quality of your commit messages — which is why good commits matter.


Splitting Large Commits

Another valuable use: when you've made too many changes without committing, AI can help you decompose the mess into logical, focused commits.

Here is a large diff with multiple unrelated changes:

[paste diff]

Help me split this into separate, logical commits.
For each commit, tell me:
- Which files/changes belong together
- What the commit message should be
- In what order to commit them

This is a rescue technique for when you've been in flow and forgot to commit frequently. AI can untangle the diff and reconstruct a clean history that looks like you committed properly all along.

Pro Tip: The Atomic Commit Rule

A good commit should be atomic — it contains one logical change that can be understood, reviewed, and reverted independently. If you need to use the word "and" to describe what a commit does ("add filter component and fix calendar bug and update styles"), it's too big. AI helps you maintain this discipline by analyzing your changes and suggesting clean boundaries.


AI-Enhanced Git Workflow Summary

Here's how AI integrates into each stage of a typical Git workflow:

📝

Writing Commits

Paste your diff → AI generates conventional commit message → you review and commit.

🌿

Branch Planning

Describe your feature → AI suggests branch name and scope → you create the branch.

🔎

PR Review

Paste your diff → AI reviews for bugs, quality, performance → you address findings.

🧩

Conflict Resolution

Paste both sides + intent → AI suggests merged version → you verify and apply.

📄

Changelog Generation

Paste recent commits → AI groups and summarizes → you edit and publish.

✂️

Commit Splitting

Paste large diff → AI identifies logical boundaries → you commit in clean pieces.


Common Mistakes

Git Workflow Anti-Patterns

🧪 Practical Exercise

Find a recent commit you've made — ideally a messy one with a vague message. Then practice these AI workflows:


Key Takeaways

Previous Chapter AI and System Design
Next Chapter Testing with AI