Why git push gets slower with more branches
As coding agents get better, we are pushing more code than before. Almost all of this code first goes on a development branch before being merged into a release / shared branch. I was recently going through some of my side projects and noticed that the number of branches in each of them had ballooned.
I wanted to better understand the impact of these branches on git push itself.
My hypothesis: the more branches the repo has, the slower every push gets.
Testing it
I forked the Linux kernel repo (1.5 million commits, plus its own 955 branches and tags) and added agent branches to it: extra branches named agent/a<number>/b<number>, each pointing to its own small commit, like a finished task would. I set up four servers, with 1,000, 10,000, 100,000 and 1,000,000 agent branches.
The client is one agent, a7. It has all of Linux's history but none of the other agents' commits, like an agent that fetched only what it needed for its task. Each push sends one new commit to a new branch, and every number is the median of 5 runs.
| Agent branches on the server | Push |
|---|---|
| 1,000 | 0.32 s |
| 10,000 | 0.38 s |
| 100,000 | 1.01 s |
| 1,000,000 | 7.6 s |
Up to 10,000 branches, you'd hardly notice. At a million, the same one-commit push was more than 20x slower:
Most people push to GitHub, so I ran the same kind of test there too. I made a private repo with a tiny README and filled it with agent branches, 1,000 at a time. At each size I timed 5 pushes of one new commit to a new branch, from a clone that has only main:
| Agent branches on GitHub | Push |
|---|---|
| 0 | 1.58 s |
| 1,000 | 1.65 s |
| 10,000 | 2.15 s |
| 50,000 | 4.38 s |
| 100,000 | 6.81 s |
On GitHub, 100,000 branches made a push more than 4x slower, and it already showed at 10,000. That's a bigger jump than on my local server, where 100,000 branches added 0.7 seconds. I can't see inside GitHub's servers, so I can't say where the extra time goes. It's also one run on one repo, over the internet, with an older git (2.34) on the client, so treat these numbers as a direction, not a threshold.
So the hypothesis holds. To see why, let's look at what a push does with all those branches.
Where the branches come in
In How git push works we went through the five steps of a push. Three of them go through every branch on the server, even branches the push has nothing to do with:
- The server lists every branch (step 1). Before the client sends anything, the server sends it every branch name and the commit that branch points to. At a million branches that list is 75 MB. Fetch can ask for only the branches it wants, but push can't: fetch uses the newer version of git's protocol (the rules for what the client and server say to each other), and push never got it.
- The client looks up every commit on the list (step 2). To work out what to send, the client checks whether it already has each listed commit, because the server doesn't need those again. Our agent has none of the other agents' commits, so a million lookups find nothing.
- The server reads every branch's commit (step 4). To check that nothing is missing, the server walks back from the new commit and stops at commits its branches already point to. Before it starts, it reads the commit of every branch.
The client also goes through the list once more at the end. To line up the columns of the result line (* [new branch] …), it works out a short hash for every branch on the list.
Each of these gets slower as the branches pile up (seconds, median of 5 pushes):
| Agent branches | 1. Server lists branches | 2. Client looks up commits | 4. Server checks the push | Printing the result | Whole push |
|---|---|---|---|---|---|
| 1,000 | 0.01 | 0.03 | 0.18 | 0.00 | 0.33 |
| 10,000 | 0.04 | 0.03 | 0.20 | 0.01 | 0.42 |
| 100,000 | 0.19 | 0.11 | 0.44 | 0.12 | 1.04 |
| 1,000,000 | 1.71 | 0.93 | 3.20 | 1.19 | 7.7 |
Step 4's column is the server's whole check, not only reading the branches' commits. Building the pack with the new commit (the pack is the bundle of objects the client sends) took about 0.1 seconds at every size. At a million branches, these four steps add up to 7.0 of the 7.7 seconds.
GitHub sends the full list too. At 100,000 branches, my test repo's list had 100,026 entries (about 7 MB).
What you can do
First, check whether this affects you. Count the branches on your server:
On my local server, a push barely changed up to 10,000 branches. On GitHub, 10,000 branches already added half a second to every push, and 100,000 added five.
Wherever your repo lives, including GitHub:
- Delete branches once they're done. It speeds up all three steps without any server settings, and on GitHub it's the direct way to make the list shorter. GitHub has a repo setting, "Automatically delete head branches", that deletes a branch when its pull request is merged. It's off by default, and it was off on both of my repos. Agent branches that never become a pull request, or get abandoned, need a cleanup job (
git push origin --delete <branch>). - Reuse a branch per agent if your agents work on one task at a time and your pull-request flow allows it, so the branch count grows with the number of agents, not the number of tasks. (I didn't benchmark this.)
- Have agents fetch only the branch they need, for example
git clone --single-branch --branch main <url>. At a million branches, our agent with Linux history only pushed in 7.8 seconds, against 18.7 for one with a full clone. - Use
git push -qin agent scripts. It skips the result line, and with it about a second at a million branches.
If you run your own git server
You can hide other agents' branches from a push with receive.hideRefs. You also need core.alternateRefsCommand=true. While the server checks the push, the new objects sit in a temporary folder, and step 4 gets a second branch list through it. That second list ignores hideRefs, and the setting turns it off:
The ! line keeps the pushing agent's own branches visible, because the server refuses to create, update or delete a hidden branch. Whatever starts receive-pack on your server has to pass these settings for each agent.
| Agent branches | Default | Hidden | Hidden + alternateRefsCommand |
|---|---|---|---|
| 1,000 | 0.32 s | 0.33 s | 0.32 s |
| 100,000 | 1.01 s | 0.51 s | 0.34 s |
| 1,000,000 | 7.6 s | 2.9 s | 0.69 s |
Even with both settings, push can't ask for only the branches it needs, the way fetch can. Next: what happens when many agents push to the same branch, and what all the refused pushes do to the server.
Local tests: git 2.56.1 on one machine (AMD Ryzen 5 3600), November 2026, client and server on the same machine, no network, pinned to the same 4 CPU threads. Timing tables are the median of 5 runs of a normal git push. The per-step times come from git's performance trace (GIT_TRACE2_PERF) on 5 more pushes per size, as medians of each step. The GitHub test used git 2.34.1 over HTTPS from the same machine, one ascending run on one private repo, 5 pushes per size. Branch counts for verify-cloud and VS Code are from git ls-remote --heads on November 27, 2026. Scripts: experiments/refs.