← BlogGuides · 4 min

git worktree vs branch, stash and clone: which one, when

A branch is a line of commits, a worktree a folder to work on one, a stash parks changes, a clone copies the repo. The same hotfix done four ways, real output.

A branch is a line of commits. A worktree is a folder where a branch is checked out. They aren’t alternatives: every worktree has a branch (or a detached commit) in it. The real choice is how you get to a second branch while the first one has unfinished work in it, and there are four ways. Switch branch in the same folder, stash first and then switch, add a worktree, or clone the repository again. Short version: switch when the folder is clean, stash for a quick detour, use a worktree when both pieces of work need to stay open, and clone only when you want a fully separate repository.

New to worktrees? How to use git worktree walks through one from start to finish; this page is about when to reach for one.

To show the difference I ran the same situation four times: I’m halfway through a change to login.js on main, and a fix on the hotfix branch needs testing now.

Switch branch Stash, then switch Worktree Second clone
Your unfinished change Blocks the switch, or comes along Put away, then put back Stays where it is Stays where it is
Folders One One One per branch in use One per clone
Both branches open at once No No Yes Yes
History and branches Shared Shared Shared: a commit shows up everywhere at once Separate: push and fetch to share
.git in the new folder No new folder No new folder A one-line file pointing to the main .git A full .git directory
Same branch in two places One folder, one branch One folder, one branch Not allowed Allowed
From the runs below, Git 2.50.1, October 4, 2026.

1. Switch branch: blocked by your own work

Terminal window
$ git switch hotfix
error: Your local changes to the following files would be overwritten by checkout:
login.js
Please commit your changes or stash them before you switch branches.
Aborting

If your changes don’t touch a file that differs on the other branch, Git switches and carries them along, which is its own kind of surprise. With an edit to README.md instead, switching to a new branch and back, the M says the change traveled with me:

Terminal window
$ git switch -c side
Switched to a new branch 'side'
$ git switch main
Switched to branch 'main'
M README.md

Either way, one folder holds one branch at a time. Switching is the right tool when the folder is clean.

2. Stash, switch, come back

Terminal window
$ git stash push -m 'half-finished login feature'
Saved working directory and index state On main: half-finished login feature
$ git switch hotfix
Switched to branch 'hotfix'
$ git switch main
Switched to branch 'main'
$ git stash pop
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: login.js
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (f3be58750a75bea16c9269b2c2f5958dc5c5a676)

Fine for a five-minute detour. It falls apart when the detour is long (a build, a test suite, a review), when you forget what’s in the stash, or when pop conflicts with what you did in between. And while you’re on hotfix, your main work doesn’t exist anywhere you can run it.

3. A worktree: both stay open

Terminal window
$ git worktree add ../app-hotfix hotfix
Preparing worktree (checking out 'hotfix')
HEAD is now at fddae88 Fix login
$ git status --short
M login.js

Your half-finished change is untouched in ~/code/app, and hotfix is checked out in ~/code/app-hotfix. Run the tests there, commit there, and the commit is visible from the main folder straight away, because both folders share one repository:

Terminal window
$ git log --oneline -2 hotfix
8cba795 Test the hotfix
fddae88 Fix login

Two things to know. A branch can only be checked out in one worktree, so from the main folder:

Terminal window
$ git switch hotfix
fatal: 'hotfix' is already used by worktree at '~/code/app-hotfix'

And the stash is shared: a stash made in one folder is listed in every other.

Terminal window
$ git stash push -m 'demo' && git -C ../app-hotfix stash list && git stash pop -q
Saved working directory and index state On main: demo
stash@{0}: On main: demo

The worktree’s folder has only tracked files: no node_modules, no .env. Every way to create one is in git worktree add, and how to get rid of it is in git worktree remove, prune and lock.

4. A second clone: fully separate

Terminal window
$ git clone -q . ../app-clone
$ git -C ../app-clone log --oneline -1 origin/hotfix
8cba795 Test the hotfix

A clone is a whole new repository with its own .git directory. That independence is the point and the cost: when I committed again in the worktree, the clone didn’t see it until it fetched.

Terminal window
$ git -C ../app-clone log --oneline -1 origin/hotfix
8cba795 Test the hotfix
$ git -C ../app-clone fetch -q
$ git -C ../app-clone log --oneline -1 origin/hotfix
5c76b7a One more fix

The difference on disk is in that .git:

Terminal window
$ file ../app-hotfix/.git ../app-clone/.git
../app-hotfix/.git: ASCII text
../app-clone/.git: directory

A clone makes sense when you want isolation from the repository itself: different Git config, a different remote, an experiment you’ll throw away whole, or a checkout of the same branch twice (which worktrees don’t allow). For a second branch on the same machine, a worktree does the same job without a second copy of the history.

Which one I’d use

  • Folder clean, quick look at another branch: switch.
  • Five-minute interruption: stash.
  • Two pieces of work that both need to stay open, such as a long test run, a review, or a hotfix while a feature is half done: a worktree.
  • Two or more AI coding agents at once: one worktree each. Agents run tests and read git status constantly, so sharing a folder means each sees the other’s half-done edits. That’s the case the worktrees guide is about, with how Claude Code and Codex create their own.
  • A fully separate repository: clone.

Questions people ask

Is a git worktree the same as a branch?

No. A branch is a named line of commits. A worktree is a folder where one branch (or one commit) is checked out. You can have many branches and only one folder, or one worktree per branch you're actively working on.

Should I use git worktree or git stash?

Stash for a quick switch you'll undo in minutes. A worktree when both pieces of work need to stay open: two things running, a long review, or two AI agents working at once. Stashes are shared between all worktrees of a repository.

Is a git worktree better than cloning the repository twice?

For work on the same machine, usually. A worktree shares the history and the branches with the original folder, so a commit in one is visible in the other at once. A second clone is a separate repository: commits only travel between clones through push and fetch.

Try it on your own repo.

Free for one card at a time.

Get Pro

Seats, you included (2–50)
3
VAT included. Businesses in the EU can add a VAT number on the payment page.Founding price, kept for as long as your subscription runs.

Checking your sign-in…