> ## Documentation Index
> Fetch the complete documentation index at: https://docs.diversion.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# worktree

> Add, list, or remove worktrees: extra clones of a repository

A worktree is an extra clone of the current repository, with its own workspace, in another directory. Run these commands from inside a clone. For how worktrees work, see [Worktrees](https://docs.diversion.dev/basic/worktrees.md).

## add

```bash theme={null}
dv worktree add [path] [-b <branch>] [--ref <ref>] [--link] [--setup]
```

Creates a new workspace of this repository and clones it into `path`. Give at least one of `path`, `-b`, or `--ref`.

`[path]` is where to create the worktree. A single name, like `my-task`, creates `diversion-worktrees/<repo>/my-task` next to the current clone. The path cannot be inside the current clone. Without `-b` or `--ref`, the worktree is on the branch named after the last part of the path, and that branch is created from the current commit if it does not exist. With `-b` or `--ref` and no path, the directory is named after the branch or commit.

`[-b <branch>]` creates a new branch for the worktree, from `--ref` or from the current commit. Fails if the branch exists.

`[--ref <ref>]` checks out a branch name, branch ID, commit ID, or tag ID. With `-b`, it is where the new branch starts.

`[--link]` symlinks the dirs listed under `link:` in the repository's `.dvworktree.yml` from the current clone, so the worktree shares them instead of building its own.

`[--setup]` runs the `setup:` command from the repository's `.dvworktree.yml` in the new worktree. The command gets the current clone's path in the `DV_WORKTREE_ORIGIN` environment variable. Use it only with refs you trust.

## list

```bash theme={null}
dv worktree list
```

Lists the worktrees of this repository on this computer, with their path, branch, and workspace ID.

## remove

```bash theme={null}
dv worktree remove <path> [-f]
```

Deletes the worktree's workspace, stops syncing its directory, and deletes the directory. It does not remove a main clone; for that, use [unregister](https://docs.diversion.dev/cmd-ref/unregister.md).

Without `-f`, it first rescans the worktree and waits for the sync. It then refuses if the worktree has uncommitted changes, conflicts, conflict backups, or a submodule, or if the worktree is paused. For changes and backups, the error is:

```
<path> has uncommitted changes or conflict backups. Commit them, clear the backups with dv conflict-backups clear, or use -f to delete them with the worktree
```

`[-f]` removes the worktree anyway and deletes its uncommitted changes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.