6.2CORE PATH

Git Discipline For Ai-generated Code

v1 covered git. This section is what changes when an agent is the one making most of the commits.

When you're vibe coding, git is your seatbelt. The agent will sometimes rewrite your file in a way you don't want. The agent will sometimes "clean up" code that wasn't broken. The agent will sometimes invent a solution that looks like progress but is actually moving you sideways.

Git is how you survive these situations.

THE RULES:

COMMIT BEFORE EVERY AGENT RUN. Before you ask the agent to do anything substantive, commit your current state with a message like "working state before [task]." If the run goes badly, you git reset back to that commit.

BRANCH PER FEATURE. Don't let agents work on main. Create a branch (git checkout -b feature/customer-search), let the agent work there, review the result, merge to main only when you're satisfied.

READ EVERY DIFF. Before merging, run git diff main..feature/your- branch (or use the GitHub/GitLab UI). Read every line. Don't merge diffs you haven't read.

NEVER FORCE-PUSH TO SHARED BRANCHES. Force-pushing rewrites history and can erase other people's work. If you don't know what force-pushing is, that's fine. It means you'll never accidentally do it.

WRITE COMMIT MESSAGES THE AGENT CAN UNDERSTAND. "Fix login" is bad. "Fix login: validate email format before database lookup, return 400 on missing fields, add rate limit tracking" is good. The next agent session will read your commit history; help it understand what's been done.

USE TAGS FOR RELEASES. When you ship a version that works, tag it (git tag v0.1.0). If a later change breaks something in production, you can roll back to the tag in seconds.

A practical workflow:

$ git status # clean working tree $ git checkout -b feature/inventory # new branch $ git commit --allow-empty -m "starting inventory feature"

... ask the agent to do the work ...

$ git diff # review the agent's changes $ git add . $ git commit -m "Inventory feature: low-stock alerts, vendor reorder UI" $ git checkout main $ git merge feature/inventory # merge after review

If something goes wrong mid-way: $ git reset --hard HEAD # nuke uncommitted changes $ git checkout main # go back to main $ git branch -D feature/inventory # delete the broken branch

Try again with a better spec.

Curriculum last updated 2026-04-30