Syntax
Description
Removes worktrees whose branches have been merged to main. By default, only removes merged worktrees. With the-a flag, removes all worktrees.
This command is useful for cleaning up completed work after branches have been merged.
Aliases
c- Short alias for clean
Options
Remove all worktrees, not just merged ones. Use with caution as this removes worktrees with uncommitted changes.
Behavior
Default Mode (Merged Only)
- Scan - Finds all worktrees for current repo
- Filter - Identifies worktrees with branches merged to main
- Preview - Shows list of worktrees to be removed
- Confirm - Asks for confirmation before removal
- Remove - Removes each worktree and updates registry
All Mode (-a flag)
- Scan - Finds all worktrees for current repo
- Preview - Shows all worktrees to be removed
- Confirm - Asks for confirmation
- Remove - Removes all worktrees
Interactive Flow
Clean Merged Worktrees
Clean All Worktrees
Examples
Clean merged worktrees
Clean all worktrees
Using short flags
Check before cleaning
Merge Detection
A worktree is considered “merged” when:- All commits from the branch are in main
- The branch can be safely deleted
- The worktree is no longer needed
When No Worktrees to Clean
- No worktrees exist
- No worktrees have been merged (in default mode)
Cancellation
You can cancel the operation at the confirmation prompt:- Select “No”
- Press ESC
- Press Ctrl+C
Force Removal
The clean command uses force removal (--force flag with git) to handle:
- Uncommitted changes (when using
-a) - Untracked files
- Modified worktrees
Branch Handling
Theclean command only removes worktree directories. Git branches remain in the repository.
To also delete branches:
gwt merge which removes both.
Safety Warnings
Using --all Flag
No Confirmation per Worktree
Unlikegwt remove, the clean command asks for confirmation only once at the beginning. All selected worktrees are removed in batch.
Typical Workflow
After Merging PRs
Weekly Cleanup
Fresh Start
Comparison with Other Commands
| Command | Selection | Confirmation | Branches |
|---|---|---|---|
gwt clean | Merged only | Once | Keeps |
gwt clean -a | All | Once | Keeps |
gwt remove | Interactive | Per worktree | Keeps |
gwt merge | Single | Per operation | Deletes |
Exit Codes
0- Success (worktrees cleaned or operation cancelled)1- Error (not in a git repository)
Related Commands
- gwt status - Check merge status before cleaning
- gwt remove - Remove worktrees interactively
- gwt merge - Merge and remove a single worktree