Skip to content

Add worktree cleanup to merge-pr command #1165

@dyoshikawa

Description

@dyoshikawa

Summary

When merging a PR from a worktree branch, the merge-pr command should clean up the worktree using git gtr rm {worktree_name}.

Motivation / Purpose

When using git gtr worktrees for development, merging a PR leaves behind the worktree directory and its associated branch. The merge-pr command already has a "Clean Up Local Branch" step (Step 6), but it doesn't handle the worktree case. Adding worktree detection and cleanup will streamline the post-merge workflow.

Details

Modify .rulesync/commands/merge-pr.md Step 6 ("Clean Up Local Branch") to detect if the current environment or the merged branch is associated with a worktree, and if so, clean it up using git gtr rm.

Proposed changes to Step 6

Add worktree detection logic:

  1. Check if the merged branch is associated with a worktree (e.g., via git worktree list)
  2. If a worktree is found for the branch, run git gtr rm {worktree_name} to remove it
  3. If no worktree is associated, fall back to the existing cleanup behavior (git checkout main && git pull --prune && git branch -d <branch-name>)

Files affected

  • .rulesync/commands/merge-pr.md

Additional Context

git gtr rm handles both the worktree directory removal and the associated branch deletion, so it replaces the need for separate git branch -d when dealing with worktrees.

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintainer-scrapRough notes for AI implementation. Not for human eyes.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions