Clean up finished Git worktrees.
wtree shows each worktree's age, local changes, and GitHub pull request state. Review the cleanup plan before you remove finished worktrees.
brew install filipgutica/tap/wtreeInspect your worktrees
In your Git repository, run wtree for a table or wtree ui for the interactive browser. Age uses the last commit by default. To use another timestamp, pass --age-by checkout or --age-by created. Closed PRs can contain unmerged work, so check each proposed removal.
Browse
wtree — demo-api · 5 worktrees · 2 removable overall Rows 1–5 of 5 · s sort: age · p PR: all · filter: none · age: commit delete branches: off · 0 selected o open · ? help · q quit · Space select · Enter details · / filter · n new BRANCH AGE PR FLAGS PATH ▏ [-] main 2d - M@ ~/code/demo-api [-] spike/flink-cdc 8mo - * ~/code/demo…link-spike [ ] chore/bump-deps 5mo closed #4390 ~/code/demo…-bump-deps [ ] feat/usage-charts 3mo merged #4502 · [-] fix/token-refresh 4h open #4821 * · ╭──────────────────────────────────────────────────────────────────────────────╮ │ main 2d old │ │ path ~/code/demo-api │ │ PR none │ │ state clean · unpushed unknown │ │ remove blocked: main worktree; you are inside it │ │ head 0671a0fbdd8378fe8a2beedbe63440e0a7abfe4d │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ [-] protected · M main · @ current · * dirty · path: · default blocked: main worktree; you are inside it · main — ~/code/demo-api
wtree ui In wtree ui, move between rows with the arrow keys. The panel below the table shows details of the focused worktree.
Select worktrees
wtree — demo-api · 5 worktrees · 2 removable overall Rows 1–5 of 5 · s sort: age · p PR: all · filter: none · age: commit delete branches: off · 2 selected o open · ? help · q quit · d review 2 · Space select · Enter details · / filter BRANCH AGE PR FLAGS PATH [-] main 2d - M@ ~/code/demo-api [-] spike/flink-cdc 8mo - * ~/code/demo…link-spike [x] chore/bump-deps 5mo closed #4390 ~/code/demo…-bump-deps ▏ [x] feat/usage-charts 3mo merged #4502 · [-] fix/token-refresh 4h open #4821 * · ╭──────────────────────────────────────────────────────────────────────────────╮ │ feat/usage-charts 3mo old │ │ path ~/.wtree/demo-api/feat/usage-charts │ │ PR merged #4502 · Usage charts │ │ state clean · unpushed unknown │ │ remove available after review │ │ head c6d048ec51635e797cb1e0b211a28c18f14a3b18 │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ [x] selected · M main · @ current · * dirty · path: · default selected ~/.wtree/demo-api/feat/usage-charts
SpacePress Space on each worktree you want to remove. Check the selection count beside d. Press d to review the selection.
Review removal
wtree — confirmation
y remove 2 Esc cancel b branches
DELETE WORKTREES — also delete branches: NO
will remove: 2
REMOVE ~/.wtree/demo-api/feat/usage-charts (3mo, merged)
REMOVE ~/code/demo-api-bump-deps (5mo, closed)
skipped: 0dCheck the paths and branch deletion setting before removal. Press y to remove the listed worktrees. To go back, press Esc.
List worktrees
BRANCH AGE PR FLAGS PATH main 2d - M@ ~/code/demo-api spike/flink-cdc 8mo - * ~/code/demo-api-flink-spike chore/bump-deps 5mo closed #4390 ~/code/demo-api-bump-deps feat/usage-charts 3mo merged #4502 · fix/token-refresh 4h open #4821 * · flags: M main @ current * dirty ↑ unpushed L locked P prunable d detached ✓ in default branch path: · in ~/.wtree/<repo>/<branch> 2 worktrees have merged/closed PRs — run wtree clean --done
wtree At a terminal, wtree adds a command hint when the listed rows include merged or closed PRs, or prunable worktrees.
Preview cleanup
remove (2): BRANCH AGE PR PATH - chore/bump-deps 5mo closed ~/code/demo-api-bump-deps - feat/usage-charts 3mo merged ~/.wtree/demo-api/feat/usage-charts dry run. drop --dry-run to remove them.
wtree clean --done --dry-run Check each worktree under remove. Blocked matches appear under skip, with the reason.
Read the table
- PR
- Pull request state: open, merged, or closed.
-means no PR.?means wtree could not get its state. - M @
Mmarks the main worktree.@marks the worktree that holds the current directory, or the-C <dir>directory when you pass-C.- * ↑
*means uncommitted changes.↑means unpushed commits, which wtree counts only on branches with an upstream.- [-]
- A blocked row in the browser. Space cannot select it. The status line explains why and whether f can override the block.
- ✓
- The branch's commits are in the default branch. This check misses squash and rebase merges because they rewrite commits. Use the PR column for those.
- ·
- The path is the default location,
~/.wtree/<repo>/<branch>.
Preview a cleanup, then run it
From a worktree you will keep, preview a cleanup based on PR state:
wtree clean --done --dry-run--done matches merged or closed pull requests.
If the plan is correct, run the same cleanup without --dry-run:
wtree clean --done At the confirmation prompt, enter y to remove the planned worktrees. To remove just one by name, use wtree rm <branch-or-path>. It requires an exact match and follows the same confirmation and safety rules.
Set up wt to change directory
wtree prints paths because a program cannot change its parent shell's directory. The wt shell function changes into the path that go, new, path, or ui prints.
| Command | What it does | |
|---|---|---|
eval "$(wtree shell-init zsh)" | Run this line now to enable wt in this shell. Add the same line to ~/.zshrc for future shells. For bash, replace zsh with bash. Add that line to ~/.bashrc. | |
wt go | Pick a worktree or branch and change into its directory. wt new and wt path also change directory. In wt ui, press o to enter the focused worktree. |
Commands
Repository commands use the Git repository in the current directory. Pass -C <dir> to use another one.
| Command | What it does | |
|---|---|---|
wtree | List worktrees, with main first and the rest oldest first. | |
wtree ui | Inspect worktrees and choose which to remove in the interactive browser. | |
wtree clean --older-than 30d --dry-run | Preview removal of worktrees older than 30 days. Add --done to require a merged or closed PR too. | |
wtree rm feat/example | Remove one worktree after confirmation. Replace feat/example with its exact branch name or path. Substrings never match. | |
wtree prune --dry-run | Preview stale Git worktree records to prune. Drop --dry-run to review and confirm pruning. | |
wtree new feat/example | Create a worktree and print its path. If the branch already has a live worktree, print that path instead. | |
wtree path feat/example | Print an existing worktree path. Accepts an exact branch, exact path, or unique substring. | |
wtree go | Pick a worktree or branch and print its path. A branch without a worktree gets one. Uses fzf if installed. | |
wtree --size | Measure disk usage with du. This is off by default because it is slow on large worktrees. | |
wtree --json | Print the worktree list as JSON. | |
wtree clean --help | Show every cleanup filter and option. Use --help with any command for its reference. |
Keys in wtree ui
Press ? in the browser to see every shortcut.
| Key | What it does |
|---|---|
| ↑ / ↓ | Move between worktrees. |
| Space | Toggle selection of the focused worktree. A blocked row stays unselected. The status line explains why. |
| / | Filter by branch or path. Enter applies the filter. Esc cancels it. |
| p | Cycle the PR filter: all, merged or closed, open, and no PR. |
| a | Select every removable worktree in the filtered list. |
| c | Clear all selections. |
| d | Review selected worktrees for removal. With nothing selected, review the focused worktree if it is removable. |
| b | Toggle branch deletion. You can also change it on the review screen. |
| f | Toggle forced selection. Overrides only uncommitted changes, unpushed commits, or a lock. Main and current stay protected. |
| Enter | Show the full branch name and path of the focused worktree. |
| o | Quit and print the path of the focused worktree. With wt ui, change into that directory. |
| n | Create a worktree for a branch. |
| r | Reload worktrees and fetch PR state again. |
| q / Esc | Quit from the list, or go back from the review without removing anything. |
Safety and exit codes
- Confirmation
clean,rm, andpruneshow a plan before asking for confirmation.--yesskips the question and runs the removal.--dry-runonly prints the plan.- Cleanup scope
cleanneeds a filter such as--doneor--older-than 30d, or--allto consider every non-main worktree. Barewtree cleantries to open the browser only when stdin and stdout are terminals and--yes,--dry-run, and--jsonare absent; see the full reference for details.- Branches
- Branches stay by default. To request branch deletion, pass
--delete-branchor turn it on with b in the browser. - Protected worktrees
- The protected worktrees are the main worktree and the one that holds the current directory (or the
-C <dir>directory). They are never removed, even with--force. Uncommitted changes, unpushed commits, and locks block removal unless you pass--forceor select with f. Forced removal can discard uncommitted work. - PR state
- PR state is cached for 10 minutes by default.
--refreshbypasses the cache. Without a usable cache, missing, signed-out, or offlineghleaves PR state unknown. A cleanup that filters on PR state then exits 3 and removes nothing. It reports an error instead of reporting no matches. - Pipes and scripts
- Without
--dry-runor--yes,clean,rm, andpruneprint the plan and exit 2 when either stdin or stdout is not a terminal and there is something to remove. Forcleanandrm,--jsonalso requires one of those flags when there is something to remove; see the full reference for script usage. - Interactive browser
wtree uirequires terminals on stdin and stderr. If either is not a terminal, it exits 2 instead of starting. Stdout can be a pipe so the shell function can receive a path.