Skip to main content

What are Git Worktrees?

A git worktree creates a new working directory that shares the same .git repository as your main directory. This allows you to have multiple branches checked out simultaneously, each in its own directory, all backed by a single git object store.
Think of worktrees as “multiple checkouts of the same repository” without duplicating the entire git history.

Anatomy of a Worktree

When you create a worktree, git establishes: Isolated per worktree:
  • Working directory (files on disk)
  • Branch checkout
  • Index (staging area)
  • HEAD reference
Shared across all worktrees:
  • Object store (commits, trees, blobs)
  • Refs and branches
  • Config and remotes
  • Hooks

Why Worktrees Solve Parallel Agent Problems

The Problem: Shared Working Directory

Running multiple coding agents in the same working directory causes chaos:

The Solution: Isolated Worktrees

With worktrees, each agent works in complete isolation:

How Superset Uses Worktrees

Workspace Creation

When you create a workspace in Superset:
  1. Superset runs: git worktree add <path> -b <branch>
  2. Git creates:
    • A new directory at <path>
    • A new branch <branch> (or checks out existing)
    • Metadata in .git/worktrees/<name>
  3. Superset configures:
    • Terminal sessions in the worktree directory
    • Port allocation for isolation
    • Setup scripts execution

Workspace Deletion

When you delete a workspace:
  1. Terminal sessions are gracefully terminated
  2. Teardown scripts run (if configured)
  3. Git worktree is removed: git worktree remove <path> --force
  4. Metadata is cleaned up from .git/worktrees/
Worktree deletion is permanent. Any uncommitted changes in the worktree will be lost.

Worktree Isolation Benefits

File Isolation

Each worktree has its own files on disk. Agents can edit, create, and delete files without affecting other worktrees.

Branch Isolation

Each worktree checks out a different branch. Commits in one worktree never interfere with commits in another.

Dependency Isolation

Install different package versions in each worktree. Run npm install or bun install independently.

Process Isolation

Start dev servers, build processes, or test runners in each worktree. Different ports, different processes.

What’s NOT Isolated

Some things are shared across all worktrees:
  • Git history: All worktrees see the same commits and branches
  • Remote tracking: Fetches and pushes affect all worktrees
  • Git configuration: Settings in .git/config apply everywhere
  • Hooks: Pre-commit, post-merge hooks run in all worktrees

Branching Strategy

Superset uses a simple, effective branching strategy:

Default Branch Naming

By default, workspace branches are named:
Examples:
  • agent/add-oauth
  • agent/fix-memory-leak
  • agent/refactor-api-v3
You can customize the branch prefix in SettingsWorkspace DefaultsBranch Prefix.

Custom Branch Prefixes

Configure custom prefixes per project or globally:
  • feature/ - For new features
  • fix/ - For bug fixes
  • refactor/ - For refactoring tasks
  • experiment/ - For experimental branches
  • Custom prefix of your choice

Base Branch Selection

When creating a workspace, choose which branch to base it on:
  • main / master - Default for most projects
  • develop - If using git-flow
  • staging - For staging environment changes
  • Any existing branch in your repository
The workspace will branch off from your selected base:

Cleaning Up Worktrees

Automatic Cleanup

Superset handles most cleanup automatically:
  1. On workspace delete: Worktree is removed and metadata cleaned
  2. On app close: Terminal sessions are gracefully terminated
  3. On project close: All worktrees remain on disk for later use

Manual Cleanup

If Superset crashes or worktrees become orphaned:
If you manually delete a worktree directory without using git worktree remove, git doesn’t immediately know. The metadata in .git/worktrees/ persists.Run git worktree prune to clean up stale metadata:
This is safe to run and only removes metadata for worktrees that no longer exist on disk.

Importing Existing Worktrees

If you have worktrees created outside Superset:
  1. Open the New Workspace dialog (⌘N)
  2. Click the Import tab
  3. Superset scans .git/worktrees/ for existing worktrees
  4. Click Import all or select individual worktrees
Superset will create workspace entries for these worktrees without re-creating them on disk.

Worktree Location Configuration

By default, Superset creates worktrees in:
You can customize this location:

Per-Project Location

  1. Open Project Settings (gear icon in sidebar)
  2. Set Worktree Base Directory
  3. New workspaces will be created in the custom location

Global Default Location

  1. Open SettingsWorkspace Defaults
  2. Set Default Worktree Directory
  3. Applies to all new projects
Changing the worktree location only affects new workspaces. Existing workspaces remain in their current location.

Advanced Worktree Operations

Locking Worktrees

Git allows locking worktrees to prevent accidental removal:
Superset respects locked worktrees and won’t delete them.

Worktree Aliases

Speed up worktree management with shell aliases:

Worktree Health Check

Periodically verify worktree integrity:

Worktree Performance Characteristics

Creation Speed

Worktrees are 10-20x faster than cloning because they don’t duplicate the git object store.

Disk Usage

Worktrees use 50-80% less disk space than full clones because they share the object store.
For a 500 MB repository, each worktree adds approximately 250-400 MB of working files, but 0 MB of git history.

Git Version Requirements

Superset requires Git 2.20+ for full worktree support. Check your git version:
If you’re on an older version, upgrade:

Common Pitfalls and Solutions

Error: fatal: 'path' already existsCause: A worktree already exists at that pathSolution:
Error: fatal: 'branch' is already checked outCause: Git prevents the same branch from being checked out in multiple worktreesSolution: Each worktree must use a different branch. Create a new branch or switch to a different one.
Error: Worktree shows in git worktree list but doesn’t exist on diskCause: Worktree was deleted manually instead of via git worktree removeSolution:
Cause: Hooks are shared across all worktrees by defaultSolution: Hooks run in all worktrees. If you need worktree-specific hooks, use environment variables to detect which worktree is active:

Best Practices

One Task Per Worktree

Keep worktrees focused. Create a new worktree for each discrete task or feature.

Clean Up Merged Worktrees

Delete worktrees after merging their branches. Reduces clutter and disk usage.

Use Descriptive Paths

Name worktree directories after the task, not just the branch. Makes navigation easier.

Prune Regularly

Run git worktree prune periodically to clean up stale metadata.

Further Reading

Next Steps

Workspaces

Learn how Superset manages worktrees as workspaces

Configuration

Configure setup scripts for worktree initialization

Agents

Run coding agents in isolated worktrees

Presets

Automate workspace creation with presets