Why switching branches rebuilds so much of your app

A branch switch rewrites files, and the build goes by what was rewritten. What decides how much the next build redoes, and five ways to keep it small, from worktrees to compilation caching.

Because the build goes by which files were written, not only by what’s in them. When you switch branches, git rewrites every file that differs between the two, and the next build recompiles each one. Then it recompiles the files that use any declaration that changed, and every file in a target whose build settings differ. Two branches a few commits apart cost little. A branch that started from last month’s main, or that changes a build setting or a package version, can cost close to a clean build. And the switch back costs the same again, even though nothing in those files is new to your Mac. The fixes: keep a second worktree for the branch you visit, keep branches close to main, and keep settings and package versions out of branch-to-branch churn.

The short version

What differs between the branches What the next build redoes What helps
Nothing, but you looked at another branch and came back Every file git rewrote on the way Don’t switch to look: a second worktree, or git show
Code inside function bodies Those files Keep branches close to main
A type’s declarations, or a module’s public interface Those files, and the files in any module that use what changed Smaller modules with stable interfaces
A build setting on a target Every file in that target, or in every target for a project-wide setting Keep settings the same on every branch
A package version The package, and what’s built on it Update packages on main, in one commit

What a switch does to your files

Git doesn’t store modification times. When it checks out a branch, it writes the files that differ and stamps them with the current time. The Git FAQ explains why: “Git sets the current time as the timestamp on every file it modifies, but only those,” so that build tools, which “compare the timestamp of the source(s) with the timestamp of the derived file(s)”, rebuild what changed (Git FAQ).

That’s the right behavior: it never leaves you running stale code. But it means the build sees a rewritten file as a changed file. We checked this on a small three-module test project with Xcode 27.2: touching a file without changing a byte recompiles it. Switch to another branch to read some code, switch straight back without building, and the next build recompiles every file git rewrote both ways, even though each one is exactly what you built an hour ago.

The build is smarter one level up. When a recompiled file turns out to declare the same things as before, the files that depend on it don’t recompile, and in our test nothing linked again. So a rewritten file costs you that file. A changed declaration costs you everything that uses it.

Back from a quick look, no build in betweenFiles git rewroteThe rest of the app: kept
A branch that changed function bodiesFiles that differThe rest of the app: kept
A branch that changed a shared typeFiles that differFiles in other modules that use the type, then linkKept
A branch that changed a build setting on one targetEvery file in that targetOther targets: kept
Highlighted: work the next build redoes. From a small three-module test project on Xcode 27.2; a sketch, not to scale. On a large app each highlighted block is as big as the difference between the branches.

Four things that decide the size of the rebuild

1. How far apart the two branches are

The number of files that differ is the floor of the rebuild. A feature branch rebased on today’s main differs in the files it touched. A branch that started from last month’s main differs in everything the team changed since, and switching to it is close to a clean build. To see the size before you switch:

git diff --stat HEAD other-branch | tail -1

2. Which declarations changed

A change inside a function body stays in its file. A change to what a file declares (a new property, a changed signature, a new case) recompiles the files that use it, and across modules, the files in modules that import it and use what changed. In our test, adding one internal method to a shared type recompiled the file in the next module that used the type, then linked again. Our article on why a one-line change rebuilds so much covers this in detail; a branch switch is the same thing, for every change on the branch at once.

3. Build settings and packages

A target’s compiler settings are part of every compile. If a branch adds a flag, a preprocessor macro or a different Swift version to one target, every file in that target recompiles on the switch, and again on the way back, though no source changed. In our test, a flag on one module recompiled all of that module’s files; a project-wide flag recompiled every file in the app. A branch that changes Package.resolved makes the build resolve packages again and rebuild the ones whose versions changed, along with what’s built on them.

4. Scripts and generated files

A code generator or script that writes its output again on every run, even when the output is the same, has the same effect as a switch: the build sees new files. Apple’s guidance: “Xcode uses a script’s input and output files to determine when to run it,” so declare both, and without them, “Xcode runs custom scripts during every build cycle” (Improving the speed of incremental builds). A generator that compares before it writes, and leaves an unchanged file alone, saves the recompile.

What helps

Keep a second worktree instead of switching

A worktree is a second checkout of the same repository in another folder, on another branch. Git’s documentation: it allows “you to check out more than one branch at a time” (git-worktree).

git worktree add ../MyApp-review review-branch

Xcode keeps a separate build folder for each copy of a project on disk, so each worktree stays warm for its own branch: your feature branch keeps its build, and the review branch keeps its own. What it costs: the first build in a new worktree is a full build, each worktree takes the disk space of a checkout plus its build folder, and git won’t check out the same branch in two worktrees at once. Keep one or two long-lived worktrees and reuse them, rather than making a new one for each review. If you run coding agents in worktrees, the same applies; see your coding agent spends its day waiting on builds.

Don’t switch just to look

To read a file on another branch, git show other-branch:path/to/File.swift prints it without touching your checkout. To see what a branch changed, git diff main...other-branch or the pull request page. Neither rewrites a file, so neither costs a build.

Keep branches close to main

Rebase or merge main into a long-running branch often. The switch then costs the branch’s own changes, not a month of everyone else’s. Small, short-lived branches help twice: fewer files differ, and fewer shared declarations do.

Keep settings and packages the same on every branch

Put build settings in .xcconfig files on main, and change them there, in their own commits, rather than on feature branches. Commit Package.resolved and update packages on main in one commit, so every branch builds the same versions. Then a switch between two branches costs the code that differs, and not a recompile of whole targets.

Try compilation caching

Compilation caching is built in since Xcode 26 and off by default:

Find it Build Settings › Enable Compilation Caching

Key COMPILATION_CACHE_ENABLE_CACHING

Debug value Try Yes YES, and measure

It stores compile results by content, so the switch back to a branch you’ve built before can take them from the cache instead of compiling again. In Apple’s release notes, the workflows that “will benefit the most” are “switching between branches” and “clean builds”. In our test, every compile on the switch back came from the cache; the build log says “Cache hit” for each one. It doesn’t help a branch you’ve never built, linking and the steps after it still run, and the cache uses disk space on your Mac. Our article on Bazel, Tuist and build settings covers sharing a cache between Macs.

One thing not to do

Tools exist that set each file’s timestamp back to its last commit after a checkout, so the build sees fewer changes. Don’t use them for a build folder you switch between branches. The Git FAQ explains the risk: a file can end up older than an output built from a different version of it, and then “the derived file will not be built even if it is different”. That’s a build that runs stale code, which is worse than a slow one.

Measure your own switch

Build your branch once so it’s warm. Then switch, build with a timing summary, switch back and build again:

git switch other-branch
xcodebuild build -scheme MyApp -destination "platform=iOS Simulator,id=$SIMULATOR_ID" \
  -showBuildTimingSummary
git switch -
xcodebuild build -scheme MyApp -destination "platform=iOS Simulator,id=$SIMULATOR_ID" \
  -showBuildTimingSummary

If both builds take about as long as a clean build, look at settings and packages first: those recompile whole targets. If they scale with the size of git diff --stat, the branches are just far apart. Our guide to the build timeline shows how to see which targets took the time.

Hand it to your coding agent

To have an agent measure what a switch costs in your project and tell you why, give it this:

Read https://quickfirebuild.com/blog/switching-branches-rebuilds/. Then, in the project folder, check that the working tree is clean; if it isn't, stop and tell me. Don't commit, stash or discard anything.

Note the current branch, and call the branch I name OTHER. Run `git diff --stat HEAD OTHER | tail -1`, and list which of these differ between the two branches: project files (.pbxproj), .xcconfig files, Package.swift and Package.resolved, and files a script or code generator writes.

For the main scheme on a Simulator destination, build once to warm up. Then switch to OTHER and time a build with -showBuildTimingSummary, switch back and time another. Time one clean build too, for comparison.

Tell me both switch times next to the clean build, which of the article's four causes (distance between branches, changed declarations, settings and packages, scripts and generated files) explains most of it, and which of its fixes it suggests. Leave me on the branch I started on.

What’s left

A branch switch is a build of whatever differs between two branches, and the fixes above keep that difference small or keep you from paying for it twice. Quickfire, which we’re building, is for the builds in between: faster everyday builds of large apps, on the project you already have. It doesn’t make a branch switch faster, so the fixes above are the ones to use. Early access opens in early 2027.