---
title: "How do I work on two branches at once with git worktree?"
description: "git worktree lets you check out a second branch in its own folder from the same repository, so you can fix a bug or review a PR without stashing or cloning again."
url: https://www.danny.engineering/answer/git/how-do-i-work-on-two-branches-at-once-with-git-worktree
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Git"]
---

# How do I work on two branches at once with git worktree?

## The short answer


Use `git worktree add` to check out another branch into a separate folder. Both folders share one repository, so commits made in either are visible to both, and you never need to stash your current work.


```bash
git worktree add ../project-hotfix -b hotfix/login origin/main
cd ../project-hotfix
# work, commit, push as usual
git worktree remove ../project-hotfix
```


## Why it happens


A normal clone has one working directory, so it can only have one branch checked out at a time. Switching branches means committing or stashing what you are doing, waiting for files to change, and often rebuilding or reinstalling. Cloning the repository again works, but it duplicates the whole history and the two clones do not share branches or commits until you push and fetch.


A worktree is a second working directory attached to the same `.git` data. Each worktree has its own checked-out branch, its own staged changes and its own files on disk, but they all share commits, branches, tags, remotes and configuration. Creating one is fast because no history is copied.


## How to fix it


### Add a worktree for an existing branch


Pass a folder path and a branch name. Keeping worktrees next to the main checkout, rather than inside it, stops tools from scanning one inside the other.


```bash
git fetch
git worktree add ../project-review feature/new-checkout
```


If the branch only exists on the remote, Git creates a local branch that tracks it, as long as only one remote has a branch with that name.


### Create a new branch in a new worktree


Use `-b` to make a new branch, and give a starting point. This is the usual way to start an urgent fix while your feature branch stays untouched.


```bash
git worktree add -b hotfix/login ../project-hotfix origin/main
```


To try something out without a branch at all, use `--detach`.


```bash
git worktree add --detach ../project-scratch HEAD
```


### List, remove and tidy up


```bash
# See every worktree and its branch
git worktree list

# Remove one (refuses if it has uncommitted changes)
git worktree remove ../project-hotfix

# Clean up records of worktree folders you deleted by hand
git worktree prune
```


Removing a worktree does not delete its branch. Delete the branch separately with `git branch -d` once it is merged.


### Set up each worktree like a fresh checkout


Only tracked files appear in a new worktree. Ignored files such as `node_modules`, build output and `.env` files are not copied, so install and configure each one.


```bash
cd ../project-hotfix
cp ../project/.env.local .env.local
npm ci
```


If two worktrees run a dev server at the same time, give them different ports.


## Common pitfalls

- **"is already checked out" or "is already used by worktree".** A branch can only be checked out in one worktree at a time. Use a different branch, or switch the other worktree away first.
- **Deleting the folder with rm.** Git still thinks the worktree exists and keeps the branch locked. Run `git worktree prune`, or use `git worktree remove` next time.
- **The stash is shared.** All worktrees use the same stash list, so `git stash pop` in one can apply changes saved in another. Name your stashes or prefer commits.
- **Nesting worktrees inside the main folder.** Editors, test runners and linters may pick up the second copy. Keep them as sibling folders.
- **Moving folders by hand.** Use `git worktree move` so Git updates its records.

## Related reading

- [git-scm.com: git worktree](https://git-scm.com/docs/git-worktree)
