GitWorktree.org logoGitWorktree.org

Git Worktree in VS Code

Visual Studio Code is the most popular editor for working with git worktree. Current VS Code releases have built-in support for discovering, creating, opening, and deleting worktrees. Multi-root workspaces and separate editor windows still matter, but worktrees are no longer just an extension-driven workflow in VS Code.

Built-in Git Worktree Support

VS Code added built-in Git worktree support in version 1.103. The Source Control Repositories view can detect linked worktrees for a repository, and the Command Palette plus repository actions let you create, open, and delete worktrees without leaving the editor:

Built-in worktree actions in VS Code
# Built-in VS Code worktree actions
# Command Palette:
#   Git: Create Worktree
#   Git: Open Worktree in New Window
#   Git: Delete Worktree
#
# Source Control > Repositories view:
#   open repository actions to create, open, or delete worktrees

The integrated terminal is still useful for advanced flags such as --lock, --reason, or repair, but day-to-day worktree management no longer requires an extension.

Git Worktree VS Code Extensions: Built-in vs GitLens vs Others

Since VS Code now covers the core worktree workflow itself, extensions are optional. Here is how the options compare:

FeatureVS Code Built-inGitLensThird-party Extensions
Create worktreesYes (Command Palette)YesVaries
List worktreesYesYes (dedicated panel)Varies
Open in new windowYesYesSome
Delete worktreesYesYesSome
Branch history / blameBasicAdvanced (inline blame, graphs)No
CostFreeFree (Pro features paid)Free

When to Use GitLens

GitLens adds value when you need rich Git context alongside your worktrees: inline blame annotations, commit graphs, comparison views, and a dedicated worktrees panel with more detail than the built-in Source Control view provides. If you already use GitLens for other Git features, its worktree support is a bonus.

Do You Need a Third-Party Worktree Extension?

In most cases, no. Older extensions like "Git Worktrees" were essential before VS Code added built-in support. Now they are best treated as workflow preferences rather than requirements. If a third-party extension offers a specific UI or shortcut you prefer, it is fine to use — but the built-in features handle the standard create/list/open/delete workflow.

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

Bind VS Code's built-in Git worktree 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"
}

You Might Also Like