Skip to content

Enough Git to Supervise Your AI Coding Agent

Your AI coding agent just edited five files and said “I’ve committed the changes and pushed to GitHub.” You approved it. But what happened? Where did those changes go? And if the code is wrong, can you get back to where you were?

Git is the version control system that almost every software project uses. When you work with an AI coding agent like Claude Code, Cursor, or GitHub Copilot, the agent runs Git commands on your behalf. You don’t need to memorize those commands, but you do need to understand what they mean. Otherwise you’re approving operations you can’t verify.

This article gives you the mental model. A companion how-to guide walks through putting your project on GitHub for the first time.

What “committed” means

A Git repository is your project folder with a hidden .git directory that records its history. Every time you (or your agent) “commit,” Git takes a snapshot of the files you’ve staged and saves it with a short message describing what changed.

Your project’s history is a chain of these snapshots:

commit 3: "Add error handling to CLI"
commit 2: "Create command-line interface"
commit 1: "Initial project setup"

Each commit has a unique identifier (a long hexadecimal string like a1b2c3d). You can return to any commit in the chain. Nothing is lost unless you deliberately tell Git to throw it away.

When your agent says “I’ve committed the changes,” it means: a new snapshot has been added to this chain.

The four states of your code

Files in a Git repository move through four states. This is the core mental model that makes everything else make sense.

    graph LR
    A[Working Directory] -->|git add| B[Staged]
    B -->|git commit| C[Committed]
    C -->|git push| D[Pushed to GitHub]
  

Working directory is the current state of your files on disk. When your agent edits a file, the change exists here first.

Staged means you’ve marked specific changes to include in the next commit. Think of it as a packing list: you choose what goes into the snapshot before taking it.

Committed means the snapshot is saved in your local Git history. It exists on your machine but nowhere else.

Pushed means the commit has been sent to a remote repository like GitHub, where it’s backed up and accessible to others.

When your agent says “I’ll stage and commit these changes,” it’s moving edits from working directory → staged → committed. When it says “I’ll push to GitHub,” it’s moving committed snapshots → pushed.

The two commands worth running yourself

Even if your agent handles every other Git operation, two commands are worth knowing. They’re how you verify what the agent did before approving a commit or push.

git status

Shows where things stand: which files have been modified, which are staged, which are untracked.

$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)

        modified:   src/cli.py
        modified:   tests/test_cli.py

Untracked files:
        src/utils.py

This tells you: two files were modified and one new file was created, but nothing has been staged or committed yet.

git diff

Shows the actual changes, line by line. Green lines with + are additions. Red lines with - are deletions.

$ git diff
diff --git a/src/cli.py b/src/cli.py
--- a/src/cli.py
+++ b/src/cli.py
@@ -1,3 +1,5 @@
+import sys
+
 def main():
-    print("hello")
+    print("hello", file=sys.stderr)

This tells you: the agent added an import and changed where print sends output. You can decide whether that’s what you wanted before the change becomes permanent.

Tip

Run git status and git diff before approving your agent’s commits. They take a second and can save hours of debugging.

What branches are

Your agent might say “I’ll create a branch for this feature.” A branch is a parallel line of commits that doesn’t affect your main code until you merge it back.

    gitGraph
    commit id: "Initial"
    commit id: "Add CLI"
    branch feature
    commit id: "Try new parser"
    commit id: "Fix edge case"
    checkout main
    merge feature id: "Merge feature"
  

The main branch is the default. A feature branch lets the agent experiment without risking the stable version. When the work looks good, the branch gets merged back into main.

You don’t need to manage branches yourself. You need to know that when your agent says “I created a branch called fix-parser,” your main code is still safe.

Undoing things safely

Git’s value as a safety net depends on knowing what’s reversible. The key distinction: has the change been committed or not?

Uncommitted changes are just modified files. Your agent can restore them to their last committed state. Nothing is lost because the previous commit still exists. You can ask your agent: “Undo all the changes you just made” or “Restore src/cli.py to how it was before.”

Committed changes are part of the history. The safe way to undo them is a revert: a new commit that reverses the changes from an earlier commit. The original commit stays in the history (nothing is deleted), but its effects are undone. You can ask your agent: “Revert the last commit” or “Undo the commit that changed the parser.”

Warning

Some Git operations rewrite history rather than adding to it (like git reset --hard or git push --force). These can permanently destroy work. If your agent proposes one of these, ask why before approving.

Git vs GitHub

Git runs on your machine. It tracks your project’s history locally. You could use Git without ever connecting to the internet.

GitHub is a website that hosts a copy of your Git repository. The relationship is:

  • git push sends your local commits to GitHub
  • git pull brings commits from GitHub to your machine

Why use GitHub?

  • Backup. If your laptop dies, your code still exists on GitHub.
  • Tooling. Features like GitHub Actions, pull requests, and collaboration all require a GitHub repository.

When your agent says “I’ll push to GitHub,” it’s syncing your local history to the remote copy. When it says “I’ll open a pull request,” it’s using a GitHub feature to propose merging one branch into another.

What to ask your agent

You don’t need to type Git commands. You need to know what to ask for:

  • “Show me what changed” (triggers git diff)
  • “What’s the current status?” (triggers git status)
  • “Commit these changes with the message ‘Add input validation’” (stages and commits)
  • “Push to GitHub” (syncs to remote)
  • “Create a branch for this work” (isolates changes)
  • “Revert the last commit” (safely undoes)
  • “Show me the recent commit history” (triggers git log)

The mental model from this article lets you understand the responses.

Get Python tooling updates

Subscribe to the newsletter
Last updated on

Please submit corrections and feedback...