Skip to main content

Syntax

Description

Interactively remove worktrees for the current repository. Provides a searchable interface to select and remove worktrees one at a time. The command continues to prompt for worktrees to remove until you cancel (Ctrl+C or ESC).

Aliases

  • rm - Short alias for remove

Interactive Flow

The command provides an interactive search interface:

Examples

Remove worktrees interactively

Using the short alias

Search Functionality

The search is case-insensitive and matches against:
  • Branch name (e.g., feature-auth)
  • Worktree directory name (e.g., myapp-feature-auth)
  • Full path (e.g., /Users/john/projects/myapp-feature-auth)
Example searches:
  • Type feat - Shows all worktrees with “feat” in branch or path
  • Type auth - Shows worktrees containing “auth”
  • Type projects/ - Shows worktrees in a specific directory

Confirmation

Before removing each worktree, you’ll see a confirmation prompt:
  • Select “Yes” to remove the worktree
  • Select “No” to skip and continue searching
  • Press ESC or Ctrl+C to exit

Removal Process

For each confirmed removal:
  1. Git Command - Executes git worktree remove "<path>" --force
  2. Fallback - If git command fails, uses filesystem removal (rm -rf)
  3. Registry Update - Removes entry from ~/.gwtree/worktrees.json
  4. Confirmation - Shows success or error message
Success output:
Error output:

Continuous Mode

After removing a worktree, the search prompt appears again, allowing you to remove multiple worktrees in one session:

Exiting

To exit the remove command:
  • Press ESC during search
  • Press Ctrl+C at any time
You’ll see:

When No Worktrees Exist

If no worktrees are found:

Force Removal

The command always uses --force flag with git worktree remove to handle:
  • Worktrees with uncommitted changes
  • Worktrees with untracked files
  • Modified worktrees

Safety Features

  1. Confirmation Required - Never removes without explicit confirmation
  2. Search First - See what you’re removing before confirming
  3. One at a Time - Removes worktrees sequentially, not in batch
  4. Registry Cleanup - Automatically updates internal tracking

Branch Handling

The remove command only removes the worktree directory and registry entry. The git branch remains intact. To remove the branch as well, use:
Or use gwt merge which removes both worktree and branch.

Comparison with Other Commands

Exit Codes

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