Picture two AI agents working against the same checkout: one refactoring a utility file, the other adding a feature that happens to touch the same file. Neither agent knows the other exists. Twenty minutes later, one of them has silently overwritten the other’s edits, and the resulting diff is a tangle that belongs to neither task.
Every AI coding agent should get its own branch, for the same reason every human contributor already does. Branches exist precisely to let independent work happen without stepping on other independent work — the fact that the “contributor” is an AI agent instead of a person doesn’t change the underlying git problem at all. This post covers why one-agent-one-branch should be a default, not an occasional best practice, and how to make it effortless.
The Problem: Agents Don’t Know About Each Other
An AI coding agent operates on whatever files are in front of it. It has no visibility into another agent — or you — editing the same working directory at the same time. From git’s perspective, simultaneous edits to a shared checkout look identical whether they come from two people, two agents, or one of each: uncommitted changes get overwritten, and there’s no warning before it happens.
This isn’t a hypothetical edge case. The more useful agents get, the more tempting it is to run several at once — one on a bug, one on tests, one exploring an idea — and running more than one against a shared checkout is exactly when this failure mode shows up.
Branches Solve a Problem Git Already Solved
Git has had an answer to “how do independent lines of work coexist” since branches were introduced, and it’s the same answer whether the person committing is human or not: give each independent unit of work its own branch, and merge deliberately when it’s ready. An agent fixing a bug on agent/fix-login-bug can’t collide with an agent adding a feature on agent/add-export-csv, because they simply aren’t looking at the same files at the same moment — each branch has its own commit history until you choose to combine them.
# Give the auth-bug agent its own branch
git checkout -b agent/fix-login-bug
# Give the export-feature agent a separate one
git checkout -b agent/add-export-csv
# Each agent commits independently, no shared state
git add . && git commit -m "agent: fix login redirect loop"
A checked-out branch alone isn’t quite enough, though — checking out a different branch in the same working directory still means only one agent can be active there at a time. That’s where a git worktree comes in: pairing a dedicated branch with a dedicated worktree gives each agent both a separate history and a separate set of files on disk, which is what actually prevents simultaneous edits from colliding.
What One-Agent-One-Branch Buys You
| Benefit | Why it matters |
|---|---|
| Clean attribution | Every commit’s branch tells you exactly which task produced it |
| Safe to discard | Abandon a branch that didn’t work out without touching anything else |
| Easier review | A diff scoped to one task is far faster to review than a mixed one |
| No collision risk | Two agents can’t overwrite each other’s uncommitted work |
| Parallelism without chaos | Run five agents at once and still know what each one did |
The “safe to discard” point deserves emphasis. Agents don’t always produce a usable result on the first try. When the work lives on its own branch, throwing away a failed attempt is a one-line git branch -D, with zero risk of taking a working change down with it.
Naming Branches So They Stay Useful
A branch is only as useful as its name once you have more than two of them open. A short, consistent scheme — something like agent/<task> — keeps git branch --list readable even with a dozen agent branches active:
# List every agent branch at a glance
git branch --list "agent/*"
# Delete a branch for a task you decided not to pursue
git branch -D agent/experimental-cache-layer
For a fuller pattern — including how to fold a ticket number or agent identity into the name — see git branch naming conventions for AI workflows.
When Branches Alone Aren’t Enough
Branches solve the “whose commit is this” problem, but they don’t solve the “whose files on disk is this” problem by themselves, since checking out a different branch in one working directory still means only one branch is active there at any moment. If you’ve ever had two agents fighting over the same checkout, the fix isn’t a better naming scheme — it’s giving each one its own worktree so the files themselves are separate. How to keep AI agents from overwriting each other’s files covers that side of the problem directly, and it’s worth reading once you’re running more than one or two agents regularly, since merge conflicts in the age of AI coding agents become far more common without it.
A Walkthrough: Three Agents, One Repository
It helps to trace through an actual day. Say you kick off three agents each morning: one closing out a bug ticket, one adding a small feature, one exploring whether a dependency upgrade breaks anything. Without branches, all three would need to take turns in the same checkout — effectively serial work disguised as parallel work, since only one agent’s uncommitted changes can safely exist at a time.
With agent/fix-search-pagination, agent/add-dark-mode-toggle, and agent/try-upgrade-react-19 as three separate branches, all three can run at the same time without any coordination between them. By the end of the day you have three independent diffs to review, each attributable to exactly one task. The dependency-upgrade exploration turns out to break a test — you delete that branch and lose nothing else. The other two get reviewed and merged on their own schedule. None of that coordination cost existed in a shared-checkout version of the same day; it would have been three tasks fighting for one directory instead of three clean, mergeable results.
Protecting Main While Agents Work
One-agent-one-branch also protects the branch that matters most: whatever you deploy from. If every agent commits directly to main, a single bad diff — hallucinated API, a subtly wrong edge case — lands where it can break things for everyone immediately. Routing every agent through its own branch means nothing reaches main without a deliberate merge, which is exactly the moment your five-pass diff review workflow should happen. The branch isn’t just an organizational convenience — it’s the checkpoint that keeps an agent’s mistake from becoming a production incident.
Getting Started
- Next time you start an agent on a task, create a branch for it first — even a quick
git checkout -b agent/<task>— before letting it touch any files. - Pair that branch with its own worktree so the agent has a separate set of files on disk, not just a separate commit history.
- Adopt a naming convention now, before you have ten agent branches to sort through later.
- If doing this manually for every session feels like overhead, Agents creates a worktree and branch automatically for every session in its sidebar — no
git checkout -brequired, with a 7-day free trial and a one-time $9.99 after that.
One-agent-one-branch isn’t a new rule invented for AI — it’s the same discipline that’s kept human collaborators from clobbering each other’s work for years. Applying it to agents by default, rather than only after the first collision, is the cheapest insurance available for running more than one at a time.