GitWorktree.org logoGitWorktree.org

Git Worktree in VS Code

Visual Studio Code is the most popular editor for working with git worktree. While VS Code's built-in Git support does not have a dedicated worktree UI, the editor works well with worktrees through extensions, multi-root workspaces, and its ability to open multiple windows. This guide covers everything you need to set up an efficient worktree workflow in VS Code.

Built-in Git Worktree Support

VS Code's built-in Source Control panel understands git worktrees at a basic level. When you open a worktree directory, VS Code correctly detects the git repository and shows the checked-out branch, staged changes, and diff views. However, there is no built-in UI for creating, listing, or managing worktrees. You need to use the integrated terminal for worktree commands:

Worktree commands in VS Code terminal
# From the VS Code integrated terminal (Ctrl+`)
git worktree add ../feature-branch feature/new-feature
git worktree list
git worktree remove ../feature-branch

The main limitation is that VS Code does not provide a way to switch between worktrees from the UI. Each worktree needs to be opened in its own window, which is where extensions help.

Recommended Extensions

Git Worktree Manager

The most popular VS Code extension for worktree management. It adds a sidebar panel that lists all worktrees, lets you create new ones, switch between them, and remove them without touching the terminal.

Install Git Worktree Manager
# Install from the command line
code --install-extension ext:git-worktree-manager

# Or search in the Extensions panel (Ctrl+Shift+X):
# "Git Worktree Manager"

Key features of Git Worktree Manager:

  • Sidebar view showing all worktrees with their branches
  • One-click creation of new worktrees from branches or tags
  • Open any worktree in a new VS Code window
  • Remove worktrees with confirmation prompts
  • Integration with VS Code's command palette (Ctrl+Shift+P)

Git Worktrees

A lightweight alternative that adds worktree commands to the command palette. Less UI-heavy than Git Worktree Manager, but sufficient if you prefer keyboard-driven workflows.

GitLens

GitLens is primarily known for blame annotations and history views, but it also provides worktree awareness. It correctly shows branch information and commit history when working inside a linked worktree, making it a good companion extension.

Setting Up VS Code Workspaces with Worktrees

A VS Code workspace file lets you save a collection of folders and settings. You can create a workspace that includes multiple worktrees, making it easy to switch between them:

Multi-worktree workspace file
// my-project.code-workspace
{
  "folders": [
    {
      "name": "main",
      "path": "./my-project"
    },
    {
      "name": "feature-auth",
      "path": "./my-project-feature-auth"
    },
    {
      "name": "bugfix-42",
      "path": "./my-project-bugfix-42"
    }
  ],
  "settings": {
    "git.autoRepositoryDetection": "subFolders"
  }
}

Save this file alongside your worktree directories (in the parent folder) and open it with File > Open Workspace from File. VS Code will show all worktrees in the Explorer sidebar with their assigned names.

Opening Worktrees in New Windows

The simplest approach is to open each worktree in its own VS Code window. This gives each worktree a fully independent editor with its own terminal, source control panel, and file explorer:

Open worktree in VS Code
# Create a worktree and open it in a new VS Code window
git worktree add ../feature-login feature/login
code ../feature-login

# Or open in the current window
code -r ../feature-login

You can also use VS Code's File > Open Folder to navigate to a worktree directory. Each window will show the correct branch in the status bar.

Multi-Root Workspaces

VS Code's multi-root workspace feature lets you add multiple folders (including worktrees) to a single window. This is useful when you want to compare code across branches side by side:

Add worktree to multi-root workspace
# Add a worktree folder to your current workspace
# Use: File > Add Folder to Workspace...
# Navigate to the worktree directory

# Or from the command line, add to a workspace file:
code --add ../feature-branch

Considerations for multi-root workspaces with worktrees:

  • Each root folder gets its own Source Control provider in the sidebar
  • The integrated terminal defaults to the most recently focused folder
  • Search (Ctrl+Shift+F) spans all workspace folders by default — use the file filter to limit searches to a specific worktree
  • Tasks and launch configurations can be scoped to individual folders

Tips and Tricks

Color-Code Your Windows

Use VS Code's workbench.colorCustomizations to assign different title bar colors to each worktree window. Add this to the .vscode/settings.json inside each worktree:

Color-coded title bars
// .vscode/settings.json in your feature worktree
{
  "workbench.colorCustomizations": {
    "titleBar.activeBackground": "#1e3a5f",
    "titleBar.activeForeground": "#ffffff"
  }
}

Share Extensions Across Worktrees

VS Code extensions are installed globally (per user), not per project. All your worktree windows automatically have access to the same extensions. However, extension settings stored in .vscode/settings.json need to be committed to the repo or copied to each worktree.

Create a Keyboard Shortcut for Worktree Commands

If you use Git Worktree Manager, bind its commands to keyboard shortcuts via File > Preferences > Keyboard Shortcuts. Search for "worktree" to find available commands.

Terminal Profile for Worktree Navigation

Add a shell alias to quickly list and switch between worktrees from VS Code's terminal:

Shell aliases for worktree management
# Add to ~/.bashrc or ~/.zshrc
alias wt='git worktree list'
alias wta='git worktree add'
alias wtr='git worktree remove'

# Quick open a worktree in a new VS Code window
wto() {
  local dir=$(git worktree list --porcelain | grep "^worktree" | awk '{print $2}' | fzf)
  [ -n "$dir" ] && code "$dir"
}