Skip to content

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.

Install with Homebrew

brew install filipgutica/tap/wtree

Homebrew also installs Node.js. Install Homebrew first if you need it. For pull request state, wtree uses the GitHub CLI, gh, which must be signed in.

Runs on
macOS and Linux
Needs
Git and Node.js 20+

Inspect 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.

These examples use a demo repository and sample pull requests.

Browse

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

Space

Press Space on each worktree you want to remove. Check the selection count beside d. Press d to review the selection.

Review removal

d

Check the paths and branch deletion setting before removal. Press y to remove the listed worktrees. To go back, press Esc.

List worktrees

wtree

At a terminal, wtree adds a command hint when the listed rows include merged or closed PRs, or prunable worktrees.

Preview cleanup

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 @
M marks 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.

CommandWhat 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.

CommandWhat it does
wtreeList worktrees, with main first and the rest oldest first.
wtree uiInspect worktrees and choose which to remove in the interactive browser.
wtree clean --older-than 30d --dry-runPreview removal of worktrees older than 30 days. Add --done to require a merged or closed PR too.
wtree rm feat/exampleRemove one worktree after confirmation. Replace feat/example with its exact branch name or path. Substrings never match.
wtree prune --dry-runPreview stale Git worktree records to prune. Drop --dry-run to review and confirm pruning.
wtree new feat/exampleCreate a worktree and print its path. If the branch already has a live worktree, print that path instead.
wtree path feat/examplePrint an existing worktree path. Accepts an exact branch, exact path, or unique substring.
wtree goPick a worktree or branch and print its path. A branch without a worktree gets one. Uses fzf if installed.
wtree --sizeMeasure disk usage with du. This is off by default because it is slow on large worktrees.
wtree --jsonPrint the worktree list as JSON.
wtree clean --helpShow 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.

KeyWhat it does
↑ / ↓Move between worktrees.
SpaceToggle 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.
pCycle the PR filter: all, merged or closed, open, and no PR.
aSelect every removable worktree in the filtered list.
cClear all selections.
dReview selected worktrees for removal. With nothing selected, review the focused worktree if it is removable.
bToggle branch deletion. You can also change it on the review screen.
fToggle forced selection. Overrides only uncommitted changes, unpushed commits, or a lock. Main and current stay protected.
EnterShow the full branch name and path of the focused worktree.
oQuit and print the path of the focused worktree. With wt ui, change into that directory.
nCreate a worktree for a branch.
rReload worktrees and fetch PR state again.
q / EscQuit from the list, or go back from the review without removing anything.

Safety and exit codes

Confirmation
clean, rm, and prune show a plan before asking for confirmation. --yes skips the question and runs the removal. --dry-run only prints the plan.
Cleanup scope
clean needs a filter such as --done or --older-than 30d, or --all to consider every non-main worktree. Bare wtree clean tries to open the browser only when stdin and stdout are terminals and --yes, --dry-run, and --json are absent; see the full reference for details.
Branches
Branches stay by default. To request branch deletion, pass --delete-branch or 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 --force or select with f. Forced removal can discard uncommitted work.
PR state
PR state is cached for 10 minutes by default. --refresh bypasses the cache. Without a usable cache, missing, signed-out, or offline gh leaves 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-run or --yes, clean, rm, and prune print the plan and exit 2 when either stdin or stdout is not a terminal and there is something to remove. For clean and rm, --json also requires one of those flags when there is something to remove; see the full reference for script usage.
Interactive browser
wtree ui requires 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.