git worktree lets one repository have several working folders, each on its own branch, sharing a single object store. Run git worktree add ../hotfix -b hotfix to make a new folder on a new branch, git worktree list to see them all, and git worktree remove ../hotfix when finished. No second clone needed.
| Task | Command |
|---|---|
| New folder on a new branch | git worktree add ../app-fix -b fix/login |
| New folder on an existing branch | git worktree add ../app-review feature/cart |
| Throwaway folder at a commit | git worktree add --detach ../app-old v1.4.0 |
| See every worktree | git worktree list |
| Delete a worktree | git worktree remove ../app-fix |
| Clean up folders you deleted by hand | git worktree prune |
Updated
Stashing, switching and rebuilding every time someone asks for a quick fix wastes time. A worktree gives you a second checkout of the same repo in another folder, so a long test run, a code review and an urgent patch can each live in their own directory. Use the builder to get the commands, then check the reference for the rarer subcommands.
| Subcommand | Syntax | Use it to |
|---|---|---|
| add | git worktree add [-b <new-branch>] <path> [<commit-ish>] | Create a folder and check out a branch or commit in it |
| list | git worktree list [-v | --porcelain] | Show every worktree with its HEAD and branch; --porcelain is for scripts |
| remove | git worktree remove [-f] <worktree> | Delete a clean worktree folder and its records |
| prune | git worktree prune [-n] [-v] | Forget worktrees whose folders are gone |
| move | git worktree move <worktree> <new-path> | Move a worktree folder and update git's records |
| lock / unlock | git worktree lock [--reason <text>] <worktree> | Stop a worktree being pruned, moved or removed |
| repair | git worktree repair [<path>...] | Reconnect worktrees after folders were moved by hand |
Your feature folder stays exactly as it was. The fix lives in a sibling folder and is removed once pushed.
# from inside ~/code/app, on feature/cart with uncommitted changes
git fetch origin
git worktree add ../app-hotfix -b hotfix/price-rounding origin/main
cd ../app-hotfix
npm install
# fix, test, commit
git push -u origin hotfix/price-rounding
cd ../app
git worktree remove ../app-hotfixEach worktree is a block of lines separated by a blank line: its path, HEAD hash and branch (or detached).
git worktree list --porcelain
# worktree /home/me/code/app
# HEAD 4c1d9e0...
# branch refs/heads/feature/cart
#
# worktree /home/me/code/app-hotfix
# HEAD 7a2b113...
# branch refs/heads/hotfix/price-rounding
Reviewing a pull request without disturbing half finished work, keeping a slow test suite running on one branch while coding on another, and comparing two versions of an app side by side are the classic cases.
They also suit tools that run several coding sessions on one repository: each session gets its own folder and branch, so one session's uncommitted files never leak into another's build.
All worktrees share commits, branches, tags, remotes and most config. Each has its own HEAD, index and working files, so staging in one folder does nothing to the others.
Ignored files such as .env, node_modules and build folders are not copied into a new worktree. Copy the env file over yourself and install dependencies before running anything.
A clone copies the whole repository, history included. A linked worktree shares the original repository's objects and refs and only adds a new working folder plus a little metadata, so commits made in one are instantly visible from the others without fetching.
Not by default. git worktree add refuses a branch that is already checked out elsewhere, because two folders moving one branch would overwrite each other's work. --force overrides this, but a detached HEAD or a second branch is almost always the better choice.
It refuses when the folder has modified tracked files or untracked files, so you do not lose work. Commit or clean the folder first, or pass --force. A locked worktree needs --force twice.
It deletes the leftover records git keeps for worktrees whose folders no longer exist, for example after you removed one with rm -rf. Add -n to see what it would remove first.
Use git worktree move <worktree> <new-path> so git updates its records. If you already moved it with the file manager, run git worktree repair from the new location to reconnect it.
Related: Git cheat sheet, Git rebase guide, Rename a git branch, npm commands cheat sheet.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.