Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

wt-destroy fails for nested worktree paths and merged branches #38

@davidpoblador

Description

@davidpoblador

Problem

just wt-destroy has two issues that cause it to fail in common workflows:

1. Nested paths are truncated by basename

The recipe does BRANCH="$(basename "{{ target }}")", which strips directory prefixes. When a worktree was created with a path like fix/discovery-dual-style, the worktree is registered under that full path, but basename reduces it to just discovery-dual-style. Then git worktree remove "discovery-dual-style" fails with:

fatal: 'discovery-dual-style' is not a working tree

2. No --force flag for merged branches

After a branch is merged and the PR closed, the worktree often contains untracked files (build artifacts, .env, etc). git worktree remove without --force refuses to delete it:

fatal: 'discovery-dual-style' contains modified or untracked files, use --force to delete it

Since wt-destroy is explicitly a destructive "nuke it" command (it also deletes the remote branch), it should use --force.

Suggested fix

wt-destroy target:
  #!/bin/bash
  set -euo pipefail

  # Use the target as-is for worktree removal (preserves nested paths)
  git worktree remove "{{ target }}" --force

  # Determine the branch name from the worktree's tracking branch
  BRANCH="$(git -C "{{ target }}" rev-parse --abbrev-ref HEAD 2>/dev/null || basename "{{ target }}")"

  # ... rest of recipe using $BRANCH for branch deletion

Or alternatively, just pass the target through to git worktree remove without basename, and use --force since this is the destructive variant (vs wt-rm which is the safe one).

Reproduction

just wt-add fix/my-feature
# ... do work, merge PR ...
just wt-destroy fix/my-feature  # fails with both issues

Workaround

git worktree remove fix/my-feature --force
git branch -D fix-my-feature
git push origin --delete fix-my-feature

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