all lessons · Git with an agent · 11 of 17

Stage by name

Two production regressions, one cause: git add -A

Morning: a commit meant to touch fonts and navigation collapsed the home page’s tile grid.

Afternoon, same day: a small styling commit shipped an entire unrelated feature that had been sitting half-finished in the working tree.

Both commits were made by an agent. Both used git add -A.

An agent works in a tree that other sessions, and you, have also been working in. It cannot tell your unfinished edits from its own by looking at a diff. So the only safe move is to never stage by wildcard. This is a hard rule on this machine, in the language usually reserved for secrets.

Drive it

Stage only what the subject describes

git commit -m ""

    What to try
    • Read the subject first, then the listing. Anything the subject does not describe is someone else's work, even if it is in a file you would normally touch.
    • Try staging everything and grade it. That is what git add -A does. Every leaked file is a change that will ship under the wrong description.
    • Notice the untracked rows. A draft and an env file are both ??. One is harmless to leave, the other is dangerous to add. Untracked says nothing about importance.

    The protocol

    1. Run git status and read it before staging anything. If files you did not edit appear as modified, deleted or untracked, the tree has pre-existing work. Do not absorb it.
    2. If a file you need to edit is already dirty, stop. Your change will inherit the earlier diff and the two become inseparable. Surface it: “this file already has changes; add to that work or wait?”
    3. Stage explicit paths. git add path/one path/two. Never -A, never ., never commit -a.
    4. Before every commit, run git diff --staged --stat and check that every listed file matches the subject line. A file the subject does not describe gets unstaged.
    5. If nobody asked for a commit, do not make one. Build, test, show the result. A commit is a decision point.

    Why agents make this worse

    A human running git add -A usually knows what else is in the tree, because they put it there. An agent started an hour ago has no such knowledge; the dirty files are just files. And an agent is fast, so it reaches the commit step while your other work is still in progress far more often than a person would. The rule exists because the agent’s blind spot is exactly where -A looks.

    Scope is the unit of review

    The staging rule is really a scoping rule. A commit that does one thing can be reviewed, reverted, and cherry-picked. A commit that does one thing plus whatever was lying around can do none of those cleanly. Part 5 sends non-trivial diffs to a second model for review; that review is only as good as the diff’s boundaries.

    Read the status, stage by name, check the stat, and do not commit unasked. The wildcard is how someone else’s half-finished work ships under your subject line.