Skip to content

[chore] Add merged branch and worktree cleanup script #16

Description

@ThreeLight2000

Motivation

After a pull request is merged, its local feature branch and linked worktree can remain behind. Manually checking and removing them is repetitive and makes it easy to delete the wrong branch or overlook stale worktree registrations.

Scope

  • Add a root pnpm script for cleanup.
  • Detect local branches merged into the selected mainline (prefer origin/main, with a local fallback).
  • Show candidates before changing anything and require confirmation by default.
  • Protect the current and base branches.
  • Remove eligible linked worktrees before deleting their local branches.
  • Support dry-run, non-interactive confirmation, and explicit handling of dirty worktrees.
  • Out of scope: deleting remote branches automatically.

Acceptance criteria

  • A pnpm command lists merged local branches and linked worktrees before cleanup.
  • The default flow asks for confirmation and does not remove the current or base branch.
  • Eligible clean worktrees are removed before their merged local branches.
  • Dirty worktrees are skipped unless an explicit force option is supplied.
  • Dry-run mode makes no repository changes.
  • Missing worktree registrations can be pruned safely.

Verification plan

  1. Run pnpm cleanup:merged -- --dry-run.
  2. Verify the candidate list and protected branches against git worktree list and git branch --merged.
  3. Run the script on a disposable merged branch/worktree and verify both are removed.
  4. Run the repository's relevant lint/type checks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions