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
- 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:- Superset runs:
git worktree add <path> -b <branch> - Git creates:
- A new directory at
<path> - A new branch
<branch>(or checks out existing) - Metadata in
.git/worktrees/<name>
- A new directory at
- Superset configures:
- Terminal sessions in the worktree directory
- Port allocation for isolation
- Setup scripts execution
Workspace Deletion
When you delete a workspace:- Terminal sessions are gracefully terminated
- Teardown scripts run (if configured)
- Git worktree is removed:
git worktree remove <path> --force - Metadata is cleaned up from
.git/worktrees/
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/configapply 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:agent/add-oauthagent/fix-memory-leakagent/refactor-api-v3
Custom Branch Prefixes
Configure custom prefixes per project or globally:feature/- For new featuresfix/- For bug fixesrefactor/- For refactoring tasksexperiment/- 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
Cleaning Up Worktrees
Automatic Cleanup
Superset handles most cleanup automatically:- On workspace delete: Worktree is removed and metadata cleaned
- On app close: Terminal sessions are gracefully terminated
- On project close: All worktrees remain on disk for later use
Manual Cleanup
If Superset crashes or worktrees become orphaned:What if I deleted a worktree manually?
What if I deleted a worktree manually?
If you manually delete a worktree directory without using This is safe to run and only removes metadata for worktrees that no longer exist on disk.
git worktree remove, git doesn’t immediately know. The metadata in .git/worktrees/ persists.Run git worktree prune to clean up stale metadata:Importing Existing Worktrees
If you have worktrees created outside Superset:- Open the New Workspace dialog (
⌘N) - Click the Import tab
- Superset scans
.git/worktrees/for existing worktrees - Click Import all or select individual worktrees
Worktree Location Configuration
By default, Superset creates worktrees in:Per-Project Location
- Open Project Settings (gear icon in sidebar)
- Set Worktree Base Directory
- New workspaces will be created in the custom location
Global Default Location
- Open Settings → Workspace Defaults
- Set Default Worktree Directory
- 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:Worktree Aliases
Speed up worktree management with shell aliases:Worktree Health Check
Periodically verify worktree integrity:Worktree Performance Characteristics
Creation Speed
| Operation | Time (typical) |
|---|---|
| Create worktree | 1-3 seconds |
| Clone repository | 10-60 seconds |
Disk Usage
| Item | Size |
|---|---|
| Main repository | Full size |
| Additional worktree | Only working files (~50-80% of main) |
| Worktree metadata | ~1-5 MB |
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:Common Pitfalls and Solutions
Worktree already exists error
Worktree already exists error
Error:
fatal: 'path' already existsCause: A worktree already exists at that pathSolution:Branch checked out in another worktree
Branch checked out in another worktree
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.Worktree metadata inconsistent
Worktree metadata inconsistent
Error: Worktree shows in
git worktree list but doesn’t exist on diskCause: Worktree was deleted manually instead of via git worktree removeSolution:Hooks not running in worktree
Hooks not running in worktree
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