Reference
Git Worktree Quick Reference
Use this when you need to inspect, keep, or remove work from a linked Git checkout without disturbing another working directory.
Core Model
| Term | Meaning | Check with |
|---|---|---|
| Main worktree | The normal checkout created by git clone or git init. |
git worktree list |
| Linked worktree | Another working directory attached to the same repository. | git worktree list --verbose |
| Per-worktree state | Working files, index, and HEAD. |
git status --short |
| Shared state | Objects, commits, tags, and most branch refs. | git log --oneline --decorate |
| Dirty worktree | A worktree with tracked or untracked changes. | git status --short |
Inspection Loop
List
git worktree list
Entercd <path>
Statusgit status --short
Branchgit branch --show-current
Diffgit diff
Historygit log -5
Commands
| Command | Use when |
|---|---|
git worktree list |
Show the main worktree and all linked worktrees. |
git worktree list --verbose |
Show lock or prune reasons when Git has them. |
git worktree add ../task-name -b task-name |
Create a sibling worktree and a fresh branch. |
git worktree add ../task-name existing-branch |
Check out an existing branch in a new worktree, if that branch is not already checked out elsewhere. |
git worktree add -d ../scratch-test |
Create a detached throwaway worktree for experiments. |
git worktree remove ../task-name |
Remove a clean linked worktree and its metadata. |
git worktree move <old> <new> |
Move a linked worktree while keeping Git metadata connected. |
git worktree repair <path> |
Reconnect metadata after a worktree or main checkout was moved manually. |
git worktree prune --dry-run |
Preview stale metadata cleanup after a worktree path went missing. |
git worktree prune |
Remove stale metadata for missing worktree directories. |
Keep Work
- Commit it in the worktree branch.
- Push the branch before deleting any session UI.
- Cherry-pick commits into another branch when that is cleaner.
- Create a patch with
git diff > file.patchonly when a commit is not appropriate.
Remove Work
- Run
git status --shortfirst. - Prefer
git worktree remove <path>over deleting folders by hand. - Use
prune --dry-runbefore cleaning stale metadata. - Treat
--forceas a last resort after inspecting changes.
Agents View Safety
- Background coding sessions may isolate edits under
.claude/worktrees/. - Before deleting a session, find the worktree path and run the inspection loop.
- If the worktree has useful commits, keep the branch or cherry-pick the commits.
- If the worktree has useful uncommitted changes, commit them or copy a patch before removal.
- A clean removal should not require
--force.
Red Flags
| You see | Do this |
|---|---|
git worktree remove refuses because files are dirty. |
Inspect git status --short and git diff; keep or discard intentionally. |
| A branch is already checked out elsewhere. | Create a new branch for the new worktree or switch the other worktree first. |
prunable appears in git worktree list. |
The path is missing or stale; run git worktree prune --dry-run. |
| A linked worktree was moved by hand. | Use git worktree repair <path>. |
| The repo uses submodules heavily. | Be conservative; the official manual warns that submodule support is incomplete for multiple checkouts. |
Related lesson: Inspect a Git worktree before you touch it.