Git Worktree Cheat Sheet

A practical reference for using 'git worktree' to manage multiple branches in parallel without cloning repositories.

Core Concept

  • Shared .git directory retains project config (such as hooks, multiple remotes, etc.)
  • Fresh working directory for each worktree
  • Enforces branch checkout in only one worktree

Create Worktrees

Add a worktree for an existing local branch

git worktree add <path> <branch>

Example: git worktree add ../app-hotfix hotfix/login-timeout

Add a worktree and create a new branch

git worktree add -b <new-branch> <path> <start-point>

Example: git worktree add -b hotfix/cache-ttl ../app-hotfix main

Add a worktree from a remote-only branch

git fetchgit worktree add <path> origin/<branch>

Working With Worktrees

CommandAction
git worktree listList all worktrees
cd <worktree-path>Navigate into a worktree

Removing and Cleaning Up

Remove a worktree

git worktree remove <path>

Example: git worktree remove ../app-hotfix

Prune stale worktree metadata

git worktree prune

Use this if a worktree directory was deleted manually.

Common Patterns

Feature development alongside main

git worktree add ../feature-x feature/x

Hotfix while feature work is unfinished

git worktree add ../hotfix main

Multiple parallel hotfixes

git worktree add ../hotfix-a hotfix/agit worktree add ../hotfix-b hotfix/b

Recommended Naming Convention: ../wt-<branch-name> (e.g., ../wt-hotfix-login-timeout). Your future self will appreciate this.

Back to Nerd Stuff