Skip to content

fix: prevent prune from deleting worktrees with uncommitted changes#240

Merged
avihut merged 1 commit intomasterfrom
fix/prune-deletes-uncommitted-files
Feb 19, 2026
Merged

fix: prevent prune from deleting worktrees with uncommitted changes#240
avihut merged 1 commit intomasterfrom
fix/prune-deletes-uncommitted-files

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Feb 19, 2026

Summary

  • git-worktree-prune now checks each worktree for uncommitted changes or untracked files before removing it
  • Dirty worktrees are skipped with a warning message instead of silently deleted
  • Added --force / -f flag to explicitly opt-in to removing dirty worktrees

Previously, prune unconditionally passed --force to git worktree remove, which silently destroyed any uncommitted work or untracked files in worktrees being pruned. This caused data loss with no recovery path.

Test plan

  • test_prune_skips_untracked_files — verifies untracked files are preserved without --force
  • test_prune_skips_uncommitted_changes — verifies modified tracked files are preserved without --force
  • test_prune_force_removes_dirty_worktree — verifies --force removes dirty worktrees
  • test_prune_removes_clean_worktree — verifies clean worktrees still get removed normally
  • All 22 prune integration tests pass
  • All 350 unit tests pass
  • clippy, fmt, man page, and CLI docs verification all pass

🤖 Generated with Claude Code

…r untracked files

Previously, `git-worktree-prune` unconditionally passed `--force` to
`git worktree remove`, silently deleting any uncommitted changes or
untracked files in worktrees being pruned. This could cause data loss
with no way to recover.

Now prune checks each worktree for dirty state before removing it. If
uncommitted changes or untracked files are detected, the worktree is
skipped with a warning. A new `--force` / `-f` flag allows users to
explicitly opt-in to removing dirty worktrees when intended.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@avihut avihut added this to the v1.1.0 milestone Feb 19, 2026
@avihut avihut added bug Something isn't working fix Bug fix labels Feb 19, 2026
@avihut avihut self-assigned this Feb 19, 2026
@avihut avihut merged commit e5754a3 into master Feb 19, 2026
6 checks passed
@avihut avihut deleted the fix/prune-deletes-uncommitted-files branch February 19, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant