Check out two branches at once without cloning twice.
Check out multiple branches of one repo into separate working directories simultaneously. Same .git/, multiple workspaces.
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.
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>| Flag | What it does |
|---|---|
add <path> [<branch>] | Create a new worktree at <path>. |
list | List worktrees. |
remove <path> | Remove an unused worktree. |
prune | Clean up stale worktree records. |
--detach | Create a worktree with detached HEAD. |
<path>.$ git worktree add ../proj-hotfix release/1.2$ git worktree list$ git worktree lock ../proj-hotfix --reason 'paused mid-bisect'$ git worktree unlock ../proj-hotfix$ git worktree move ../old-name ../new-name$ git worktree remove ../proj-hotfix$ git worktree prune$ git worktree repair$ git worktree add ../proj-hotfix release/1.2$ git worktree list$ git worktree remove ../proj-hotfixworktree remove leaves stale records — git worktree prune cleans them.Hit each option, then Check answers. Score is recorded; Next is always open.