Skip to main content

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

flag
Remove all worktrees, not just merged ones. Use with caution as this removes worktrees with uncommitted changes.

Behavior

Default Mode (Merged Only)

  1. Scan - Finds all worktrees for current repo
  2. Filter - Identifies worktrees with branches merged to main
  3. Preview - Shows list of worktrees to be removed
  4. Confirm - Asks for confirmation before removal
  5. Remove - Removes each worktree and updates registry

All Mode (-a flag)

  1. Scan - Finds all worktrees for current repo
  2. Preview - Shows all worktrees to be removed
  3. Confirm - Asks for confirmation
  4. 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:
Shows the worktree’s branch in the output. This means:
  • 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

Output:
This happens when:
  • No worktrees exist
  • No worktrees have been merged (in default mode)

Cancellation

You can cancel the operation at the confirmation prompt:
No worktrees are removed if you:
  • 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

The clean command only removes worktree directories. Git branches remain in the repository. To also delete branches:
Or use gwt merge which removes both.

Safety Warnings

Using --all Flag

The -a, --all flag removes ALL worktrees, including those with:
  • Uncommitted changes
  • Unmerged commits
  • Active development
Use gwt status first to review what will be lost.

No Confirmation per Worktree

Unlike gwt 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

Exit Codes

  • 0 - Success (worktrees cleaned or operation cancelled)
  • 1 - Error (not in a git repository)