merge
Merge approved PR and cleanup branches/worktrees. Use after PR approval, when ready to merge, or when user says merge.
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.
| name | merge |
|---|---|
| description | Merge approved PR and cleanup branches/worktrees. Use after PR approval, when ready to merge, or when user says merge. |
| allowed-tools | Bash, Read |
Merge PR and Cleanup
Merges an approved pull request and performs automatic cleanup of branches and worktrees.
Pre-Merge Requirements
- PR has required approvals
/quality-checkpasses (no CI currently)- No unresolved review comments
Workflow
Step 1: Verify Merge Readiness
gh pr view <pr-number> --json state,reviewDecision
Verify:
reviewDecisionis "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>
Step 8: Close Related Issue (for non-main branches)
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
--forceflag - NEVER merge to main directly (always use PR)