merge

yuush10's avatarfrom yuush10

Merge approved PR and cleanup branches/worktrees. Use after PR approval, when ready to merge, or when user says merge.

⭐0stars🔀0forks📁View on GitHub🕐Updated Jan 9, 2026

When & Why to Use This Skill

This Claude skill automates the end-to-end GitHub pull request lifecycle, from verifying approval status to merging and performing comprehensive repository cleanup. It streamlines the developer workflow by handling branch deletion, worktree removal, and local repository synchronization, ensuring a clean and efficient coding environment while enforcing best practices like squash merging.

Use Cases

  • Post-Approval Workflow Automation: Automatically verify PR approvals and execute a squash-merge once the code is ready for production.
  • Repository Hygiene: Automatically delete local and remote feature branches immediately after merging to prevent branch bloat and maintain repository clarity.
  • Git Worktree Management: Identify and remove associated git worktrees after a task is completed to free up system resources and keep the workspace organized.
  • Project Management Integration: Automatically close related GitHub issues with status comments when merging to development branches, ensuring project boards stay updated without manual intervention.
namemerge
descriptionMerge approved PR and cleanup branches/worktrees. Use after PR approval, when ready to merge, or when user says merge.
allowed-toolsBash, Read

Merge PR and Cleanup

Merges an approved pull request and performs automatic cleanup of branches and worktrees.

Pre-Merge Requirements

  1. PR has required approvals
  2. /quality-check passes (no CI currently)
  3. No unresolved review comments

Workflow

Step 1: Verify Merge Readiness

gh pr view <pr-number> --json state,reviewDecision

Verify:

  • reviewDecision is "APPROVED"
  • No blocking reviews

Step 2: Merge PR

gh pr merge <pr-number> --squash --delete-branch

Flags:

  • --squash: Squash commits into one clean commit
  • --delete-branch: Delete remote branch after merge

Step 3: Sync Local Repository

# Return to main repo directory
cd /Users/yuushio/repos/personal/github.com/auto-invoice-collector

# Update main or develop branch
git checkout main && git pull
# Or for develop: git checkout develop/<phase> && git pull

Step 4: Clean Remote Tracking

git fetch --prune

Step 5: Delete Local Branch

git branch -d <feature-branch>

Step 6: Verify Remote Branch Deletion (MANDATORY)

git branch -r | grep <feature-branch>
# Should return nothing

# If branch still exists:
git push origin --delete <feature-branch>

Step 7: Remove Worktree (if exists)

# Check for worktree
git worktree list | grep <feature-name>

# Remove if found
git worktree remove ../auto-invoice-collector-wt-<name>

When merging to development branches (not main), manually close the issue:

gh issue close <issue-number> --comment "Completed in PR #<pr-number>, merged to <branch>"

GitHub only auto-closes issues for main branch merges.

Cleanup Checklist

After merge, verify:

  • Remote branch deleted
  • Local branch deleted
  • Worktree removed (if applicable)
  • Issue closed (for develop/* merges)
  • Local repo synced with remote

Prohibited

  • NEVER merge without approval
  • NEVER merge with failing quality checks
  • NEVER skip cleanup steps
  • NEVER use --force flag
  • NEVER merge to main directly (always use PR)