basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Before running an AI agent — a clean git status

    An agent edits many files at once. If everything is committed before the run, its work is exactly git diff: every edit is visible, what you don’t want rolls back with git restore, and what you do want gets committed in parts. With uncommitted edits, yours and the agent’s get mixed, and rolling back only the agent’s is no longer possible.

    What it looks like

    git status -sb
    # ## main...origin/main          ← clean: everything of yours is committed
    # … run the agent …
    git diff --stat
    #  src/views/EntryPage.astro      | 24 ++++++----
    #  src/components/mdx/Route.astro | 61 +++++++++++++++++++++++++
    git diff src/views/EntryPage.astro    # read what changed

    Then, file by file:

    What you decided Command
    the edit is wanted git add -p — piece by piece, then git commit
    the edit isn’t wanted git restore src/views/EntryPage.astro
    the agent created stray files git clean -n, then git clean -f <file>
    none of it is wanted git restore . && git clean -fd — back to the commit

    Why not rely on the agent’s own rollback

    Agents may have their own checkpoints, but those only see edits made through their editing tools. Files changed by terminal commands — npm install, a generator script, sed — don’t make it in. Git sees everything in the directory.

    For a big task — its own branch or copy

    git switch -c agent-search-page          # the agent works in a branch; main stays untouched
    git worktree add ../site-agent -b agent-search-page   # or a separate directory on the same history

    In a separate worktree the agent edits its own copy, and you can keep working in the main directory in parallel. If you don’t like the result: git worktree remove ../site-agent and git branch -D agent-search-page.