Merge PR and Clean Up
Merge a pull request using a merge commit, then prune stale local branches.
Your Task
- Identify the PR to merge:
- If a PR number or URL is provided as an argument, use that.
- Otherwise, detect the current branch and find its associated PR:
gh pr view --json number,title,state,mergeStateStatus - If no PR is found, tell the user and stop.
- Check PR is ready to merge:
- Verify the PR state is
OPEN. - Check
mergeStateStatus— if it’sBLOCKED,BEHIND, orDIRTY, warn the user and stop.
- Verify the PR state is
- Merge the PR:
gh pr merge <number> --merge- Always use
--merge(merge commit), never squash or rebase.
- Always use
Important
- Always use merge commits (
--merge), per project git preferences. - If the merge fails, show the error and do not proceed to cleanup.