Git Worktrees
How ralph-tui uses git worktrees for parallel worker isolation — lifecycle, location, and disk considerations.
Git Worktrees
Each parallel worker operates in its own git worktree — a lightweight copy of your repository with its own working directory and branch. This provides full filesystem isolation without the overhead of cloning the entire repository.
What Are Git Worktrees?
A git worktree is a linked working tree attached to your repository. It shares the same .git object store (commits, blobs, trees) but has its own:
- Working directory (separate file tree)
- Branch (checked out independently)
- Index (staging area)
This means worktrees are fast to create (no file copying beyond checkout) and disk-efficient (shared object store).
Worktree Lifecycle
Create
When a parallel group starts, ralph creates worktrees at .ralph-tui/worktrees/worker-N/ with a dedicated branch ralph-parallel/{taskId} branched from the current HEAD.
Use
The worker's ExecutionEngine runs with cwd set to the worktree path. All file changes happen in the worktree — your main working directory is untouched during execution.
Merge
After the worker completes, its branch is merged back to your main branch. The merge happens in your main working directory, not in the worktree.
Cleanup
After merge (or on failure), the worktree is removed along with its branch:
Directory Layout
Ralph automatically adds .ralph-tui/worktrees/ to your .gitignore file to prevent accidental commits of worktree directories.
Disk Space
Worktrees share your repository's object store, so they don't duplicate git history. However, each worktree contains a full checkout of your working tree files.
Estimate: Each worktree uses roughly the same disk space as your project's source files (excluding .git/, node_modules/, etc.).
Ralph checks available disk space before creating worktrees. If free space is below the threshold, worktree creation fails with a clear error message.
Reducing Disk Usage
- Lower
maxWorkers— fewer concurrent worktrees means less disk usage - Clean build artifacts — ensure
.gitignoreexcludesnode_modules/,dist/, etc. - Worktrees share history — worktrees are created at HEAD and share the repository's object store. They do not perform a shallow clone like
git clone --depth 1
Configuration
The worktree directory can be customized in your config file:
Or via CLI:
See Configuration for all options.
Crash Recovery
If ralph crashes or is force-killed during parallel execution, worktrees may be left behind. On the next run, ralph:
- Detects orphaned worktrees in the worktree directory
- Checks for uncommitted changes in each
- Cleans up orphaned worktrees and branches
- Logs what was recovered or discarded
You can also manually clean up: