# git worktree

> The `git worktree` command manages multiple working trees attached to the same repository.

## How do I work on two git branches at the same time with git worktree?

The command that allows checking out several branches at once in different directories from a single repository. Useful for reviewing a pull request or fixing a bug without stashing current work.

- Topic: Git Commands - Main
- Type: command

## Example

Wrong:

```bash
git stash
git switch hotfix
# fix, commit, switch back
git switch feature
git stash pop
```

Right:

```bash
git worktree add ../app-hotfix hotfix
cd ../app-hotfix
# fix and commit
cd -
git worktree remove ../app-hotfix
```

The hotfix gets its own folder, so the feature branch keeps its uncommitted work untouched.

## Common mistakes

- Trying to check out a branch that is already checked out in another worktree.
- Deleting a worktree folder by hand, leaving stale entries until `git worktree prune`.

## Key points

- New worktrees are created outside the main folder, e.g. `git worktree add ../app-fix -b fix`.
- Each worktree installs its own dependencies and gets its own untracked files like `.env`.
- Finished worktrees are removed with `git worktree remove`, not just deleted from disk.

## Interview questions

### What is the difference between git worktree and git clone?

Worktrees share one `.git` database, so commits and branches are visible in all of them at once. A second clone is fully separate.

### How do I list all worktrees?

Run `git worktree list`. It shows each worktree folder with its checked-out commit and branch.

### Can AI coding agents work in separate worktrees?

Yes. Giving each agent its own worktree lets them edit files in parallel without overwriting each other.

## Related cards

- [git switch](https://wonderium.dev/processes/git-switch.md)
- [`git branch <branch>`](https://wonderium.dev/processes/git-branch.md)
- [git stash](https://wonderium.dev/processes/git-stash.md)
- [Parallel Agents](https://wonderium.dev/ai/parallel-agents.md)
- [Git](https://wonderium.dev/processes/git.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/git-worktree
- Last updated: 2026-11-25
