worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

[Feature request] Prune operation to batch remove trees + branches that have been merged

Open ortonomy opened this issue 8 months ago • 6 comments

Allow wt prune command which will bulk remove worktrees and branches that are already in the default branch.

ortonomy avatar Mar 30 '26 09:03 ortonomy

Thanks for the suggestion! This functionality already exists as wt step prune — it bulk-removes worktrees and branches that are integrated into the default branch.

A few examples:

# Preview what would be removed
$ wt step prune --dry-run

# Remove all merged worktrees and their branches
$ wt step prune

# Skip worktrees younger than 2 days
$ wt step prune --min-age=2d

It uses the same integration criteria as wt remove's branch cleanup (candidates show _ or ⊂ in wt list). Locked worktrees and the main worktree are always skipped. See wt step prune --help for full details.

If that's not quite what you had in mind, could you clarify what additional behavior you're looking for? A maintainer will take a look either way.

worktrunk-bot avatar Mar 30 '26 09:03 worktrunk-bot

oh, my bad, didn't see that. can I just do a bare wt remove then @worktrunk-bot to remove them. It seems obtuse to have this in ws step - what is step meant to represent? I thought step was component parts of another command. Seems weird its under that namespace.

ortonomy avatar Mar 30 '26 10:03 ortonomy

Good question! wt remove requires you to name specific branches — there's no bare wt remove that auto-discovers merged ones. So for bulk cleanup, wt step prune is the command you want.

On the naming: wt step started as the individual building blocks of wt merge (commit, squash, rebase, push), but it's grown into a home for standalone utilities too (prune, for-each, copy-ignored, etc.). The "step" framing doesn't fit those as naturally — that's fair feedback. prune is still marked [experimental], so there's room for it to move if a better home emerges. I'll leave this open for a maintainer to weigh in on whether promoting prune to a top-level command makes sense.

worktrunk-bot avatar Mar 30 '26 10:03 worktrunk-bot

Cool! Or even "wt remove --prune"

ortonomy avatar Mar 30 '26 10:03 ortonomy

That's an interesting alternative — wt remove --prune would make the connection to removal clear. Both that and a top-level wt prune have merit. I'll leave the naming decision to a maintainer since it touches the CLI surface area.

worktrunk-bot avatar Mar 30 '26 10:03 worktrunk-bot

Cool! Or even "wt remove --prune"

this could be reasonable in the future. I'm keen to keep the options for wt remove terse, and the prune command adds new options, so I won't make the change just yet

max-sixty avatar Mar 30 '26 12:03 max-sixty