Progress:
TIER 1 · MODULE 32· Basics

git worktree

Check out two branches at once without cloning twice.

🎯 What & why

Check out multiple branches of one repo into separate working directories simultaneously. Same .git/, multiple workspaces.

🧠 Mental model

A worktree is a separate working directory plus a tiny .git file pointing back at the main .git/ dir. Each worktree has its own HEAD and its own index. The object DB is shared.

🛠️ Synopsis

git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]
                 [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]
git worktree list [-v | --porcelain [-z]] [--expire <when>]
git worktree lock [--reason <string>] <worktree>
git worktree move <worktree> <new-path>
git worktree prune [-n] [-v] [--expire <expire>]
git worktree remove [-f] <worktree>
git worktree repair [<path>...]
git worktree unlock <worktree>

🎚️ Switches & options

FlagWhat it does
add <path> [<branch>]Create a new worktree at <path>.
listList worktrees.
remove <path>Remove an unused worktree.
pruneClean up stale worktree records.
--detachCreate a worktree with detached HEAD.

📦 Subcommands

add <path> [<commit-ish>] — Create a new worktree at <path>.
$ git worktree add ../proj-hotfix release/1.2
list — List worktrees with their HEAD and branch.
$ git worktree list
lock <path> [--reason <text>] — Prevent automatic pruning.
$ git worktree lock ../proj-hotfix --reason 'paused mid-bisect'
unlock <path> — Allow pruning again.
$ git worktree unlock ../proj-hotfix
move <path> <new-path> — Relocate a worktree on disk.
$ git worktree move ../old-name ../new-name
remove <path> — Remove a worktree (must be clean).
$ git worktree remove ../proj-hotfix
prune — Drop stale records for worktrees deleted out-of-band.
$ git worktree prune
repair [<path>...] — Fix back-pointers after a parent repo move.
$ git worktree repair

💡 Use cases

🧪 Examples

Side worktree to test a fix while keeping main work intact.
$ git worktree add ../proj-hotfix release/1.2
List worktrees.
$ git worktree list
Remove when done.
$ git worktree remove ../proj-hotfix

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.