- Section
- dev-tools
- Kind
- Editorial
- Reading time
- 3 min
- Updated
- 8 September 2026
Git Worktrees: Reviewing a Branch Without Losing Your Working State
For many developers, the need to switch back and forth between branches can be a real pain. When you want to review someone else's branch without losing your local changes, you may find yourself repeatedly using git stash to set your current branch aside..
Enter git worktree, a powerful command-line feature that allows a single clone of a repository to switch between branches and retain the complete working states of each, if properly managed. As a result, you can checkout a branch to review its contents while leaving your main working directory and other branches fully intact and in a usable state. However, convenience is not the whole story: worktrees add new layers of management and environmental setup for teams to manage.
A Git worktree is an alternative working directory that references the same repository as the current working tree managed by the main working directory[1].
The command syntax is straightforward to set up and preserve a fully capable alternate working area from the main working tree:
`` git worktree add `` [3]
This adds a new worktree connected to a new or existing branch..
And 'why would we not just clone a second repository to get the same branch-checkout capability?
Worktrees share repository history, allowing changes committed in any worktree to be visible in all others.
[9]
To keep track of your worktrees, you can list them with:
`` git worktree list `` [4]
To move or remove a worktree, the commands are equally simple:
`` git worktree move `` [13, 14]
As you can see, git worktree offers a powerful way to have multiple versions of a project open at once, working on different branches independently. But just like stashes, worktrees are not an entirely magical solution. In particular, you have to remember to clean up when you're done:
`` ` git worktree prune ` `` [5, 6, 13]
This unlocks worktrees you no longer use to release the related locked files for GC.
It is critical not to destroy the working-tree configuration files by deleting the worktree directory and files manually, without git worktree rm, as this [leaves configured but stale refs in the repository.[5, 6, 7, 13]
You can find worktree administrative data under $GIT_DIR/worktrees. `` [7] ``
You may have anticipated that worktrees are fully independent clones, but they share repository data.
In truth, while a developer in one worktree commits, pushes, and pulls the same as any solo clone in a separate repository, these changes are quickly shared with all worktrees. [8, 9]
When you switch between worktrees, you may find some additional external setup needed: `` git submodule update --init --recursive ` ``
`` `` [10, 11, 12]
Submodules in each worktree require individual initialization, and shared hook scripts in the main repository also affect all worktrees. Submodules and hooks require initial setup or must be considered when configured to rely on environment state or behavior dependent on the active working directory.
That's what is currently verified. But in an edit of this length, it is sensible to point out that some specifics are missing, of special importance to developers trying to manage an active, collaborative repository. Most critically, documentation on the habitual behavior of common editors, language-servers, and language-specific developer tools when multiple worktrees of one repository are open is sorely missing for a feature packed with what feels like high tooling promise.
And when it comes to IDE and build tool support, it is unclear how ignoring settings, build directories, and cache states translate when worktrees use the same covering main repository and submodules
In the end, no one tool is a magic wand.
For managing worktree access, git worktree lock and unlock
are also documented, but not yet accounted for across tools, at least based on officially retrieved documentation. While worktrees are not mere individual clones, baseline garbage collection and housekeeping of administrative files between them are collectively tasks here designated _your_ responsibility. The convenience can have its every day chores to do, but if you take good care of this, you'll find yourself neatly pruned, with a fresh worktree standing by, place-and-branch ready for working without delay.