codient/blog

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 serverPush
1,0000.32 s
10,0000.38 s
100,0001.01 s
1,000,0007.6 s

Up to 10,000 branches, you'd hardly notice. At a million, the same one-commit push was more than 20x slower:

$ time git push server agent/a7/fix-signup
To …/linux.git
* [new branch] agent/a7/fix-signup -> agent/a7/fix-signup
real 0m7.595s

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 GitHubPush
01.58 s
1,0001.65 s
10,0002.15 s
50,0004.38 s
100,0006.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:

Clientgit pushServerreceive-packat 1,000,000branches1every branch and the commit it points to1.71 s2look up each listed commithave it? the server doesn't need it0.93 sthe pack: the new commit and its files0.14 s3read the pack4read every branch's committhen check nothing is missing3.20 s5move the branchokprint the result linea short hash for every branch1.19 sgoes through every branch on the server
  1. 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.
  2. 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.
  3. 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 branches1. Server lists branches2. Client looks up commits4. Server checks the pushPrinting the resultWhole push
1,0000.010.030.180.000.33
10,0000.040.030.200.010.42
100,0000.190.110.440.121.04
1,000,0001.710.933.201.197.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).

Check yourself
The server has main and 999 other branches. You push one commit to main. How many branches does step 1 list?

What you can do

First, check whether this affects you. Count the branches on your server:

$ git ls-remote --heads origin | wc -l

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:

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:

git -c receive.hideRefs=refs/heads/agent/ \
-c receive.hideRefs='!refs/heads/agent/a7/' \
-c core.alternateRefsCommand=true \
receive-pack linux.git

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 branchesDefaultHiddenHidden + alternateRefsCommand
1,0000.32 s0.33 s0.32 s
100,0001.01 s0.51 s0.34 s
1,000,0007.6 s2.9 s0.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.