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 |
1. Switch branch: blocked by your own work
$ git switch hotfixerror: Your local changes to the following files would be overwritten by checkout: login.jsPlease commit your changes or stash them before you switch branches.AbortingIf 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:
$ git switch -c sideSwitched to a new branch 'side'$ git switch mainSwitched to branch 'main'M README.mdEither way, one folder holds one branch at a time. Switching is the right tool when the folder is clean.
2. Stash, switch, come back
$ git stash push -m 'half-finished login feature'Saved working directory and index state On main: half-finished login feature$ git switch hotfixSwitched to branch 'hotfix'$ git switch mainSwitched to branch 'main'$ git stash popOn branch mainChanges 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
$ git worktree add ../app-hotfix hotfixPreparing worktree (checking out 'hotfix')HEAD is now at fddae88 Fix login$ git status --short M login.jsYour 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:
$ git log --oneline -2 hotfix8cba795 Test the hotfixfddae88 Fix loginTwo things to know. A branch can only be checked out in one worktree, so from the main folder:
$ git switch hotfixfatal: '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.
$ git stash push -m 'demo' && git -C ../app-hotfix stash list && git stash pop -qSaved working directory and index state On main: demostash@{0}: On main: demoThe 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
$ git clone -q . ../app-clone$ git -C ../app-clone log --oneline -1 origin/hotfix8cba795 Test the hotfixA 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.
$ git -C ../app-clone log --oneline -1 origin/hotfix8cba795 Test the hotfix$ git -C ../app-clone fetch -q$ git -C ../app-clone log --oneline -1 origin/hotfix5c76b7a One more fixThe difference on disk is in that .git:
$ file ../app-hotfix/.git ../app-clone/.git../app-hotfix/.git: ASCII text../app-clone/.git: directoryA 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 statusconstantly, 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.