← ELI5 中文
GET IT AT A GLANCE

Branch vs.
worktree:
what's the
difference?

In one line: one is "which lines of work exist," the other is "which desk you spread them out on"
Desk 1 · main Desk 2 · new feature One cabinet, two desks
No. 10Inside Computers & the InternetPart 5 of 20
1

The short version

A branch = which lines of work exist. A worktree = the desk you're spreading a line out on right now.

They aren't even the same kind of thing, so "which is better?" doesn't make sense. It's like asking whether a menu or a dining table is better.

2

First, pull the two apart

BRANCH
A parallel line, stored in the cabinet
It's "content." You can have fifty branches and see no change on your computer at all: they don't take up your desk.
WORKTREE
A real folder you can open
It's the "workspace." It's the folder you can double-click into, see files in, and run things from: it takes up real space.

Put simply: a branch is one page of the ledger; a worktree is the page you've opened up in front of you.

3

By default, there's one desk

Desk: main switch Desk: new feature Note: still the same desk

When you "switch branches," it looks like a whole different world, but really on the same desk, one set of stuff gets cleared away and another set gets laid out.

That's where the hassles come from: you can't switch mid-task, you have to tidy up before switching, and when you switch back you have to lay everything out again.

One desk, shared in turns. That's the default.

4

What a worktree does: gives you another desk

One cabinet (all history)

Two folders, each with its own branch laid out, both open to view, edit, and run at the same time.

You really do get one extra folder on your computer. The left one is still your original project; the right one is the new desk. They don't disturb each other, but they draw on the same history in the same cabinet.

5

How is that different from just copying it?

MAKE A COPY
Carry a whole new cabinet home
The entire history gets duplicated, which takes up space. And the two cabinets go their separate ways: what you save in one, the other can't see, and over time they drift apart.
ADD ANOTHER DESK
Still the same one cabinet
The history is shared, so there's no extra space. What you save at desk 2, you can see right away back at desk 1: because it's literally the same cabinet.

Put simply: copying is "splitting the household"; adding a desk is "putting another desk in the same house."

6

When do you actually need it?

Mid-task, and something else catches fireNo clearing up, no switching: open another desk and fight the fire. When you come back, your work is exactly as you left it
Old and new versions side by sideOne desk holds one version. To compare, you need two
Several helpers working at onceOne desk each, so nobody touches anyone else's files. Cram them onto one desk and they'll collide
A job that takes a long time to runLet it run on this desk, move to another and keep working. No waiting around

The third one is the most common use today: when several AI helpers edit one project at the same time, this is what keeps them from colliding.

7

Two rules that keep you out of trouble

1. One line can't be laid out on two desks at once If you try, it will simply stop you. The reason is simple: if two desks edit the same line at once, nobody knows which one to believe in the end.
2. Clear away a desk when you're done Otherwise folders pile up, and the cabinet keeps thinking the desk is still in use. Removing one takes a single command, so don't skip it.
Branches are free. Desks take up room.
A branch answers "how many ways could this go?" A worktree answers "how many of those ways can I work on at the same time?" When you're unsure, ask yourself: do I want one more idea, or one more place to work at the same time?
UP NEXT

The Palm-Sized Computer (Raspberry Pi)

A Raspberry Pi for total beginners: credit-card size, costs about $50, and it's slow but can stay on forever, watching over one small daily job.

No. 12 · 5 minKeep going →
← Back to ELI5