Skip to content
build-3000
git

Git Through Your Agent

Repositories, commits and branches - your project's undo button and story book.

Before this: Working With AI Coding Agents

Objective

Understand what git records, direct your agent to commit work in meaningful steps, and recover from mistakes using history instead of panic.

Vocabulary

The words to use when directing your agent.

repository
A project folder whose full history of changes git remembers.
commit
A saved snapshot of your project at one moment, with a message describing why.
branch
A parallel line of development you can experiment on safely.
merge
Combining one branch's changes into another.
remote
A copy of the repository hosted elsewhere, like GitHub.

Understand it

The three questions after any change

git status shows what changed, git diff (via your agent) shows how it changed, git log shows the story so far. Direct your agent to show you all three whenever you resume work.

Branches make experiments cheap

Trying a risky change? Branch first. If it fails, delete the branch - main stays clean. Agents handle the mechanics; you decide when an experiment deserves its own branch.

Core concepts

History is a safety net

Every commit is a restore point. Break something? Go back to the last good commit. Small frequent commits shrink the blast radius of every mistake - including your agent's mistakes.

Commit messages are the story

Six months from now, the log is the only witness to why the code looks this way. 'Fix stuff' tells nothing; 'validate email format on signup' tells the next reader exactly what happened.

Examples

Undo via history

Agent broke the homepage? Restore the last good commit's files - no archaeology required. This single ability changes how boldly you can experiment.

Reading a good log

'add expense delete button', 'fix total ignoring currency', 'deploy v1' - six months later this log still explains the app's evolution line by line.

Common mistakes

Common mistake

Committing rarely, in giant blobs.

Fix

One logical change per commit. Tell your agent: 'Commit now' at natural checkpoints instead of end-of-day dumps.

Common mistake

Committing secrets or .env files.

Fix

Keep a .gitignore from day one and ask the agent to verify staged files before every commit.

Working with your AI agent

Standardize commit messages with your agent up front: imperative mood, one line, why-focused. Example standing rule: 'Every commit message: verb first, max 72 characters, describe the why when it is not obvious.'

Build it

The module’s real project. Your agent builds; you direct and inspect.

Project: Time Machine

Build a tiny text project entirely through git: create a repo with your agent and evolve a single ideas.txt across at least five meaningful commits, including one experiment on a branch that you deliberately discard.

Requirements

  • Repository initialized with at least five commits total
  • Each commit message follows the agreed convention (verb-first, descriptive)
  • One branch named experiment with a change that gets deleted without merging
  • Final git log tells a readable story of the file's evolution

Context for your agent

Initialize a git repository in a new folder. Coach me through evolving ideas.txt across five commits I dictate, enforcing my commit-message convention before each commit. Then create an experiment branch, make one change there, and teach me to abandon the branch cleanly. Show me git log and git status at the end and explain both outputs.

Verify it - twice

Check every item yourself first. Then hand your agent the prompt and compare verdicts.

Self-verified0/5
Functional
Security
Testing

Verification prompt - paste into your AI agent

Audit my Time Machine repository as a git reviewer. Run git log yourself if you can. Verify PASS or FAIL with evidence: (1) at least five commits touching ideas.txt, (2) every message verb-first and descriptive, (3) an experiment branch existed and its changes are absent from the final default branch, (4) no committed secrets or junk files. Then show me the single most confusing commit message and rewrite it per my convention.

Run this against “Git Through Your Agent” after your own checklist pass. Where the agent and you disagree, investigate before moving on.

Review questions

Answer out loud. If you cannot, revisit before moving on.

  1. Your agent just wrecked a working file. What is your recovery move?

  2. What belongs in a commit message that 'fixed bug' leaves out?

  3. Why create a branch before a risky experiment?

You can now

  • Direct an agent to commit in meaningful, well-described steps
  • Recover any mistake from history instead of redoing work
  • Keep secrets out of repository history

Up next

Anatomy of a Web App