Developer workflow8 min read

Install Worktrunk and run two Git worktrees on Windows

Eliminate git stash context-switching with Worktrunk: understand how shared .git object databases work, spin up parallel Windows checkouts, and keep your main branch spotless.

Ramon GoveiaEditor, PolarisonPublished Checked against official sources

Key takeaways

  1. 01Every developer knows the context-switching tax: you are halfway through a refactor with twelve modified files, a running dev server, and a failing test when an urgent hotfix or pull-request review lands. Traditional Git forces a bad choice — either bury your half-finished work in git stash (and pray nothing conflicts when you pop it) or clone the entire repository a second time, wasting gigabytes of disk space and duplicating remote history.
  2. 02Worktrees turn branch switching from a destructive pause into parallel directories. Pair Worktrunk with dedicated branches per task — especially for AI coding agents — and your main checkout stays clean.

Why this tool matters

Git already has a built-in solution called git worktree, which links multiple independent working folders to a single .git database. The problem is ergonomics: vanilla git worktree commands are verbose, make you manually invent sibling paths, and do not help you switch directories or clean up merged branches.

Worktrunk (wt) is a fast Rust CLI that wraps Git worktrees in a single ergonomic workflow. It shines especially when you run multiple AI coding agents in parallel — one agent can edit a UI branch while your main checkout stays clean for reviews or production hotfixes.

Watch the walkthrough

How Git worktrees and Worktrunk work under the hood

In a standard Git clone, .git is a directory containing both the shared repository history (objects/, refs/, config) and the per-checkout state (HEAD and the staging index). When Worktrunk creates a linked worktree, it does not copy the object database.

Instead, the new folder receives a tiny .git text file pointing back to <main-repo>/.git/worktrees/<name>, where Git stores an isolated HEAD and staging index. Commits made in one worktree are immediately visible to every other worktree, while uncommitted edits remain completely isolated on disk.

  • No duplicate Git history: every worktree shares one object database, so a second checkout only adds its working files on disk, not another copy of the repository history.
  • The Branch Lock Rule: Git forbids checking out the exact same branch in two worktrees simultaneously to prevent conflicting HEAD updates. Worktrunk handles this cleanly by creating or switching to a distinct branch per folder.
  • Parallel dev servers & AI agents: you can open two terminal windows or two IDE workspaces — one on main, one on ui-test — without invalidating build caches or interrupting running processes.
  • Portable Windows binary: Worktrunk ships as a standalone wt.exe executable with zero runtime dependencies.

How it compares to alternatives

ToolBest forMain tradeoff
Worktrunk (wt)Developers and AI-assisted workflows that spin up and tear down parallel branches daily.Extra CLI tool to install; note that wt collides with Windows Terminal's wt.exe alias unless you invoke the explicit path or alias it.
Vanilla git worktreeOccasional parallel checkouts with zero third-party tools.Verbose syntax (git worktree add -b ... ../path), manual directory naming, and manual cleanup/pruning.
git stash + git switchQuick 30-second branch switches with tiny diffs.Destroys running dev-server state, triggers full rebuilds, and risks losing untracked files or stash conflicts.
Multiple full git clonesComplete isolation when you want separate Git configs or remotes.Duplicates the entire .git history on disk and forces you to push/fetch to share local commits between folders.

Step-by-step walkthrough

  1. Verify the portable Windows executable (avoiding Windows Terminal collision)

    On Windows 11, typing bare wt in PowerShell usually launches Windows Terminal rather than Worktrunk. Download the x64 Windows release archive from GitHub, extract wt.exe, and bind its full path to $wt in your PowerShell session (or rename/alias it to wtr on your PATH). This guide was verified with Worktrunk v0.83.0.

    • Confirming & $wt --version prints the Worktrunk version proves you are invoking the right binary and not Windows Terminal.
    $wt = (Get-Item .\wt.exe).FullName
    & $wt --version
  2. Initialize an isolated scratch repository

    Create a fresh folder called git-lab and make a single initial commit. Passing -c user.name and -c user.email scopes the commit metadata to this command only, leaving your global ~/.gitconfig untouched. Git requires at least one commit on main before creating linked worktrees.

    • Using -b main ensures consistent default branch naming regardless of your local init.defaultBranch setting.
    New-Item -ItemType Directory -Path git-lab | Out-Null
    Set-Location git-lab
    git init -b main
    Set-Content README.md '# Worktree lab'
    git add README.md
    git -c user.name=Demo -c user.email=demo@example.invalid commit -m 'Start lab'
  3. Create a linked worktree with Worktrunk

    Run wt switch --create ui-test with --no-hooks and an explicit sibling --path. Worktrunk creates the ui-test branch, checks it out into ../git-lab-ui-test, and registers it in Git's worktree list. Because a child executable cannot change the parent PowerShell working directory without shell integration, use Set-Location whenever you want to enter the new folder.

    • & $wt list and git worktree list both display every linked checkout, its active branch, and its current HEAD commit.
    • If you use Worktrunk daily, run wt config shell install to enable automatic directory switching.
    & $wt switch --create ui-test --no-hooks --path ../git-lab-ui-test
    & $wt list
    git worktree list
  4. Verify independent working trees and clean up safely

    Modify README.md inside ../git-lab-ui-test and inspect git status --short in both directories. The ui-test folder reports M README.md, while your primary git-lab folder on main remains completely clean. When you finish with a worktree, remove it cleanly rather than just deleting the folder so Git unlocks the branch immediately.

    • If you ever delete a worktree folder manually in Explorer, run git worktree prune from main to remove stale metadata.
    • Remember that untracked folders like node_modules or .venv are not shared automatically — install or symlink them per worktree as needed.
    Add-Content ../git-lab-ui-test/README.md 'Preview note'
    git -C ../git-lab-ui-test status --short
    git status --short
    # When finished:
    # git worktree remove ../git-lab-ui-test --force

Worktrees turn branch switching from a destructive pause into parallel directories. Pair Worktrunk with dedicated branches per task — especially for AI coding agents — and your main checkout stays clean.

Common pitfalls

Windows Terminal hijacking the `wt` command

Windows ships wt.exe in WindowsApps for Windows Terminal. Always check Get-Command wt and either alias Worktrunk (e.g. wtr) or disable the Windows Terminal execution alias in Settings → Apps → App execution aliases.

Forgetting `.env` and `node_modules` in the new worktree

Because ignored files are not tracked by Git, your new worktree starts without .env.local or node_modules. Copy .env or use Worktrunk's post-create hook to automate setup.

Trying to check out `main` in two folders at once

Git blocks checking out the same branch twice. Create a dedicated feature or review branch (or detached HEAD) for every extra worktree.

Frequently asked questions

Why use Worktrunk with AI coding agents like Claude Code or Codex?
Running each coding agent in its own worktree prevents agents from overwriting each other's uncommitted files and lets you review diffs cleanly on separate branches before merging.
Does a worktree duplicate my entire Git history on disk?
No. All worktrees share the single `.git/objects` store. Only the checked-out working files (and any local dependencies you install) occupy extra disk space.
What happens if I commit inside `ui-test` — does `main` see it?
The commit immediately enters the shared `.git` database on branch `ui-test`, so you can run `git merge ui-test` or `git diff main..ui-test` from `main` without pushing or fetching.

Sources and methodology

Every command in this guide was run on a clean Windows machine before publishing, and the video shows that run. Versions are pinned where the project publishes them, so the output you see should match ours.

Keep reading