DevLogTechnical writing
Tutorials

Git Worktrees: Work on Multiple Branches Side by Side Without Stashing or Switching

September 27, 2026

You are mid-way through a feature branch when a production bug lands. The old reflex: git stash, git checkout main, fix, commit, git checkout feature, git stash pop, and hope nothing fought. Git worktrees remove that dance entirely.

A worktree is a second working directory attached to the same repository. You can check out multiple branches at once, each in its own folder, and switch between them by changing directories instead of running git checkout. No stashing, no lost context.

A quick history

git worktree arrived as a first-class feature in Git 2.5, released on July 29, 2015. The idea predates that moment by years, but 2.5 is where it became usable. If your Git is younger than that, you already have it.

The commands you need

The core set is small:

The -b flag creates a new branch and checks it out in one step. Without it, git worktree add ../hotfix creates a new branch named after the path's final component. To work on an existing branch instead, pass the branch name as the second argument.

A realistic walkthrough

Say you are on feature/payments in /repo. A hotfix is needed on main. Instead of stashing:

# from /repo, on feature/payments
git worktree add -b hotfix/urgent ../hotfix main
cd ../hotfix
# fix the bug, commit, push
git commit -am "fix: resolve checkout crash"
git push -u origin hotfix/urgent

Your feature branch is untouched. When the hotfix is done:

cd /repo
git worktree remove ../hotfix

That's it. git worktree list shows both directories, so you always know what is checked out where.

Removal rules worth knowing

git worktree remove is safety-conscious. It refuses to remove a worktree that has untracked files or modified tracked files — you must pass --force to override that. And you can never remove the main worktree; only linked ones can be removed. If you delete a worktree's directory by hand instead of using git worktree remove, run git worktree prune to clean up the leftover administrative files.

When to reach for it

Worktrees shine for hotfixes alongside feature work, for running tests against a release branch while developing, and for code review of a colleague's branch without disturbing your own. The main cost is disk space — each worktree is a full checkout. For the freedom of never stashing again, most developers find that a fair trade.

← More Tutorials