Disclosure: this post is from Git A, a paid code host for teams of AI agents. Most of this post is about plain Git and GitHub, and everything in the first four sections works without our product.
If you run more than one AI coding agent on the same repository, say a few Claude Code or Codex sessions each fixing a different issue, you will hit this sooner or later: they finish at about the same time, they all push to main, and most of them get this back:
! [rejected] main -> main (fetch first) error: failed to push some refs to '…' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This post explains why it happens, how bad it gets as you add agents, how to measure it on your own repo, and the setups that keep it under control.
1. Why the pushes get rejected
A push to a branch is accepted only if it is a fast-forward: the commit you send must build on the commit the branch points to right now. When ten agents start from the same main and each makes one commit, all ten commits build on the same old main. The first push to arrive is accepted and moves main. The other nine are now built on a commit that is no longer the tip, so all nine are rejected.
Each rejected agent does the right thing: it pulls (or rebases) and pushes again. But the other eight are doing the same at the same moment, so one wins and eight are rejected again. Round after round:
| Agents | Rejected pushes, if everyone retries every round |
|---|---|
| 2 | 1 |
| 5 | 4 + 3 + 2 + 1 = 10 |
| 10 | 9 + 8 + … + 1 = 45 |
| 20 | 190 |
That is N × (N − 1) / 2: the retries grow with the square of the number of agents, and every round costs each agent a fetch, a rebase and another push. For an AI agent that is also tokens: it reads the error, decides what to do, runs the commands, and sometimes "fixes" a rebase it didn't need to touch.
This is not a GitHub problem as such; any Git server enforces fast-forward pushes. It is what happens when many writers race for one branch tip.
2. Measure it on your own repository
Numbers from someone else's repo only go so far. This script reproduces the race on your own repo, with your own network. It:
- clones your repo once and creates a throwaway branch (it never touches
main), - makes N more clones, and in each one commits one new file,
- pushes all N at the same moment, each retrying with
pull --rebaseuntil it is in, - prints the rejected pushes, how many changes landed and the wall time, then deletes the branch.
It needs bash 5 or newer and git, and only talks to the repo URL you give it. Use a small test repository: it makes N full clones.
#!/usr/bin/env bash # measure-rejected-pushes.sh: N agents push at the same moment, count rejected pushes. # Usage: bash measure-rejected-pushes.sh <repo-url> [agents] # Needs bash 5+ and git. Uses a throwaway branch, never main, and deletes it at the end. set -euo pipefail URL="$1"; N="${2:-5}" WORK="$(mktemp -d)"; BR="race-$$-$RANDOM" git clone -q "$URL" "$WORK/base" git -C "$WORK/base" switch -q -c "$BR" git -C "$WORK/base" push -q -u origin "$BR" for i in $(seq 1 "$N"); do git clone -q --branch "$BR" "$URL" "$WORK/a$i" echo "agent $i" > "$WORK/a$i/agent-$i.txt" git -C "$WORK/a$i" add "agent-$i.txt" git -C "$WORK/a$i" commit -q -m "agent $i: add agent-$i.txt" done agent() { # push; on rejection, catch up and try again local i="$1" rejected=0 until git -C "$WORK/a$i" push -q origin "HEAD:$BR" 2>/dev/null; do rejected=$((rejected + 1)) git -C "$WORK/a$i" pull -q --rebase origin "$BR" done echo "$rejected" > "$WORK/rejected-$i" } start=$EPOCHREALTIME for i in $(seq 1 "$N"); do agent "$i" & done wait end=$EPOCHREALTIME total=$(cat "$WORK"/rejected-* | awk '{s += $1} END {print s}') git -C "$WORK/base" fetch -q origin "$BR" landed=$(git -C "$WORK/base" log --oneline FETCH_HEAD | grep -c "agent [0-9]*: add" || true) awk -v n="$N" -v r="$total" -v l="$landed" -v a="$start" -v b="$end" \ 'BEGIN {printf "agents=%d rejected_pushes=%d changes_on_branch=%d seconds=%.2f\n", n, r, l, b - a}' git -C "$WORK/base" push -q origin --delete "$BR" rm -rf "$WORK" Run it with 5 and then 10:
bash measure-rejected-pushes.sh git@github.com:you/test-repo.git 5 bash measure-rejected-pushes.sh git@github.com:you/test-repo.git 10 Each agent changes a different file, so there is never a real conflict: every rejection is pure waiting. Even against a bare repository on the same laptop, our runs came out at exactly 10 and 45. Over the internet, each round also costs a network round trip or three, and that's where the seconds go.
3. What we measured
We ran this kind of test against GitHub.com on 2 November 2026, with scripted agents and no human in the loop, median of 5 runs:
| Situation | Agents | GitHub.com |
|---|---|---|
| Each agent changes a different file | 5 | 13.25 s, 10 rejected pushes |
| Each agent changes a different file | 10 | 27.17 s, 45 rejected pushes |
| Same file, each in its own place | 10 | 26.43 s, 45 rejected pushes |
Conditions: the Express.js repository (6,183 commits), one laptop on a home connection in Kolkata, a private repository on GitHub.com, CI not included, one repository, one location. Your numbers will differ with your repo and your distance to the server.
Twenty-seven seconds doesn't sound like much. But it happens every time a batch of agents finishes, the rejected agents each run several rebases, and it doesn't include CI. Run 10 agents through a working day and it adds up.
4. Setups that help on plain Git and GitHub
These are what we used before we built our own host, roughly from cheapest to most robust.
One working folder per agent. Never let two agents share a checkout: they will fight over the index, the stash and each other's half-written files. git worktree gives each agent its own folder and branch, sharing one object store:
git fetch origin git worktree add ../agent-1 -b agent/1/fix-login origin/main git worktree add ../agent-2 -b agent/2/add-export origin/main # start each agent in its own folder; when done: git worktree remove ../agent-1 Tell each agent how to finish. Put it in AGENTS.md or CLAUDE.md, so they don't improvise with force pushes:
## Finishing a task - Work only in your own worktree and branch. - Run the tests before you finish. - Push your branch and open a pull request. Never push to main. Never force-push. A branch and a pull request per agent. Nothing is rejected, because nobody pushes to the same branch. The cost moves to review and merge: every change is a pull request, a CI run and a merge wait, and when many PRs merge in a row, later ones can fall out of date and need another CI run.
A merge queue on top of that keeps main green when many PRs are ready at once. It adds waiting time per change and CI minutes per queue entry; for a handful of agents that is usually fine.
A retry loop, if your agents do push straight to main (small repos, trusted agents):
until git push origin HEAD:main; do git pull --rebase origin main || { echo "real conflict: stop and ask"; exit 1; } done It is correct and simple; it is just quadratic, as section 1 shows. Add a small random sleep before each retry so the agents stop colliding in lockstep.
Don't split work by file to avoid conflicts. It sounds tidy, but it forces you to plan around Git instead of around the task, and two agents still need the same package.json sooner or later.
5. What we built instead (our product, disclosed)
We built Git A because we wanted many agents on one main without the retry rounds. On the same test, same day and same conditions (Git A hosted in Mumbai, near-equal network distance: 67 ms to github.com, 59 ms to git--a.com):
| Situation | Agents | GitHub.com | Git A |
|---|---|---|---|
| Different files | 10 | 27.17 s, 45 rejected pushes | 0.69 s, no retries |
| Same file, different places | 10 | 26.43 s, 45 rejected pushes | 0.57 s, no retries |
When two agents add different things at the same spot, or change neighbouring lines, both changes usually land. When they change the very same lines, one of them hears back at once which lines clashed, redoes its part, and loses nothing.
How to try it with your own agents:
- Create an organization at git--a.com, pick its region and add prepaid credit (plans from $10 a month, the smallest top-up is $25; there is no free tier, and agents are free, never seats). Outside India you pay online with PayPal, in USD.
- Bring a repository over:
ga import https://github.com/you/repo, thenga pushit to your new Git A repository. Every commit ID stays the same, andga exportsends it back.gacomes from Downloads in your organization and runs on 64-bit Linux. Plain git works too (git remote add gita https://git--a.com/you/repo.git, thengit push gita main), but the numbers above were measured withga. - Connect each agent over MCP. For Claude Code, one line per repository, with the agent's own key in
GITA_TOKEN:
claude mcp add --transport http gita https://git--a.com/api/v1/repos/acme/api/mcp \ --header "Authorization: Bearer $GITA_TOKEN" In Claude, ChatGPT, Cursor or VS Code you can add https://git--a.com/mcp as a connector and sign in instead; no key to copy.
- In the repository's settings choose Ask me (you approve every agent change) or Auto when checks pass.
- Start your agents. Each one works in its own lane and finishes with a proposal; you follow each change in the live panel or with
ga propose status.
Limits, honestly: one region today (Mumbai, on AWS), so if you are far from India expect more latency than we had; the ga command line is 64-bit Linux only for now (agents elsewhere connect over the web or plain git); one repository and one location in our measurement. Credits are prepaid and final. If you don't run agents in parallel, plain GitHub is the simpler choice.
Full conditions of every number: git--a.com/vs-github. The script, with its checksum: git--a.com/measure
Takeaways
- With N agents racing for one branch, rejected pushes grow like N × (N − 1) / 2.
- Measure it on your own repo before you redesign anything; the script above takes a minute.
- On plain Git: one worktree per agent, clear finishing rules in
AGENTS.md, and PRs or a jittered retry loop depending on how much you trust the agents. - If you run many agents every day, a host built for that removes the retry rounds altogether.
What does the script print for your repo? We'd like to know how the numbers change with distance to the server.
This article was written by an AI assistant working for Git A. The script was run before publishing (it printed 10 and 45 on a local test repository), and every number is from our published measurement at git--a.com/vs-github.
