G

Skill Entry

Git worktrees for isolation

Uses Git worktrees to create isolated working directories attached to the same repository, each on a different branch, so parallel experiments or long-running tasks do not interfere with the main working tree or require repeated stash-and-reapply cycles. This is especially useful when one branch requires a heavy build or test run while work continues on another.

Category Operations
Platform Codex / Claude Code
Published 2026-04-04
gitworktreeisolation

Use cases

  • Working on a feature branch that requires a 20-minute build while simultaneously starting work on a new feature branch
  • Running CI-heavy tests on one branch while reviewing or merging code on another branch in the same repo
  • Comparing the behavior of two branches side-by-side without switching contexts and losing uncommitted work
  • Rebasing or interactive editing a long-running branch while keeping the main branch clean and deployable
  • Reviewing a colleague's branch locally without disturbing your own uncommitted work

Key features

  • Create a dedicated worktree for each branch using git worktree add, specifying a unique directory path outside the main repo folder
  • Do heavy edits, builds, or test runs in the isolated worktree without affecting the main working tree
  • Periodically rebase the worktree branch onto the main branch to catch integration conflicts early rather than at merge time
  • When the worktree branch is merged, delete the worktree and prune the branch reference to keep the repository clean
  • Use git worktree list to track all active worktrees and their associated branches

When to Use This Skill

  • When a branch requires a long build or test run that would block other work
  • When needing to work on two branches simultaneously without stashing uncommitted changes
  • When reviewing or testing a colleague's branch locally while preserving your current working state

Expected Output

Isolated worktree directories, each on a named branch, with a clean lifecycle from creation to deletion after merge.

Frequently Asked Questions

What are the limits of how many worktrees I can create?
Git worktrees share the same object database, so disk usage is minimal, but each worktree must be on a unique branch. You cannot create a worktree for a branch that already has an existing worktree or the main checkout.
Can I push to remote from a worktree?
Yes, git push from a worktree behaves normally. The remote sees the branch normally regardless of which worktree it is pushed from.
What happens to my worktree if I force-push or delete the branch it is on?
The worktree directory remains but the branch reference becomes orphaned. You will see a warning when entering the directory. Either recreate the branch or delete the orphaned worktree with git worktree prune.

Related

Related

3 Indexed items