Skip to content

Feature request: Add --force flag to clean --merged to remove worktrees with uncommitted changes #157

@maro114510

Description

@maro114510

Feature Request

Summary

Add a --force / -f flag to git gtr clean (specifically for --merged) that bypasses the dirty-worktree safety check. This allows removing worktrees even when they contain uncommitted changes or untracked files.

Current Behavior

Currently, clean --merged skips any worktree that has uncommitted changes or untracked files to prevent accidental data loss.
(Reference: _clean_should_skip in lib/commands/clean.sh)

While this is a sensible default, it can be tedious when you know the changes are disposable (e.g., build artifacts or experimental logs) and the branch is already safely merged.

Proposed Change

Add -f / --force to the clean command. When this flag is provided:

  • The uncommitted changes check is skipped.
  • The untracked files check is skipped.

Note on Safety:

  • This flag only bypasses the "dirty" check.
  • It does not imply --yes. Users will still be prompted for confirmation unless --yes is also provided.
  • Detached HEAD worktrees and the current active worktree should still be protected/skipped.

Usage

# Force remove merged worktrees even if dirty
git gtr clean --merged --force

# Combined with auto-confirm
git gtr clean --merged -f --yes

I'm happy to contribute and open a PR if the approach looks good to you. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions