# Git Worktree VSCode Guide: Create, Open and Delete Worktrees

_VS Code has built-in Git worktree support. Create a worktree from the Source Control Repositories view, open it in its own window, and remove it with **Git: Delete Worktree...** from the Command Palette._

## The Fix

Create a worktree:

1. Open the **Source Control Repositories** view.
2. Select the repository, open the **More Actions** menu (`...`), and choose **Worktrees > Create Worktree**.
3. Pick a branch and a location. VS Code creates the folder and checks out the branch there.

Open it by right-clicking the worktree in the Repositories view and choosing **Open Worktree in New Window** or **Open Worktree in Current Window**. Each worktree shows up as its own repository in that view, and **File > Open Recent** switches between worktree folders.

Worktrees you made with `git worktree add` in a terminal show up too. The `git.detectWorktrees` setting controls that scan, and `git.detectWorktreesLimit` caps it at 50 by default.

Delete a worktree:

1. Commit, stash or copy out anything you want to keep.
2. Open the main repository folder, not the worktree you are removing.
3. Run **Git: Delete Worktree...** from the Command Palette.

This removes the folder but keeps the branch. **Git: Migrate Worktree Changes...** moves a worktree's uncommitted changes, including untracked files, into the main worktree first. It does not move commits.

## Copy Ignored Files Into New Worktrees

A new worktree has no `.env`, `node_modules` or other files that `.gitignore` excludes. Two experimental settings fill the gap:

| Setting | What it does |
|---|---|
| `git.worktreeIncludeFiles` | Copies files that match its glob patterns and are also ignored by Git |
| `git.worktreeSymlinkFolders` | Symlinks matching ignored folders that hold no tracked files |

A symlinked folder is shared, so a change made from one worktree shows up in all of them. Deleting a worktree also deletes the ignored files in its folder, even when Git reports no changes.

## Agents in Worktrees

In the **Agents** window, choose **New Worktree** and a base branch when you start a session. The agent edits a separate working directory and branch, starting from the committed files on that base branch. Commit what you want to keep, then merge the branch or open a pull request. **Chat: Open Worktree Cleanup** commits each listed session's non-ignored changes to its branch and removes the worktree folders, which reclaims disk space. Starting an agent in a worktree from the chat view is still experimental and Insiders-only.

## How Treq Handles It

Treq creates its own [workspaces](/docs/concepts/workspaces) under `.treq/workspaces/` instead of Git worktrees. Each one is an ordinary directory, so you open it in VS Code like any folder. [Managing workspaces](/docs/tutorials/managing-workspaces) shows where they live.

## Sources

- [Git branches and worktrees in VS Code](https://code.visualstudio.com/docs/sourcecontrol/branches-worktrees)
- [Work with agents in worktrees](https://code.visualstudio.com/docs/agents/run/worktrees)

## Related

- [Zed worktrees](./zed-worktrees.md)
- [Cursor worktrees](./cursor-worktrees.md)
- [What are Git Worktrees?](/learn/concepts/git/git-worktrees)
