Merge to Main: Complete PR Workflow
Merges current branch to main via GitHub PR with squash merge and branch cleanup
- 💡 Use Case:
- Completing feature work by merging to main through the proper PR workflow
- 📤 Expected Output:
- PR merged to main, branch deleted, local main updated
Prompt Content
description: Merge current branch to main via GitHub PR allowed-tools: Bash(git status), Bash(git branch), Bash(git log), Bash(git push), Bash(gh pr create), Bash(gh pr merge), Bash(gh pr list), Bash(gh pr view), Bash(git checkout), Bash(git pull) model: haiku
Merge to Main
I have gathered information about your branch. Here are the results:
<current_branch>
!git branch --show-current
</current_branch>
<branch_status>
!git status --short
</branch_status>
<commits_ahead>
!git log main..HEAD --oneline
</commits_ahead>
<existing_pr>
!gh pr view --json number,title,state,mergeable --jq '"PR #\(.number): \(.title) [\(.state)] mergeable: \(.mergeable)"' 2>/dev/null || echo "No PR exists for this branch"
</existing_pr>
Instructions
-
Check for uncommitted changes - if there are uncommitted changes, stop and ask the user to commit first.
-
Verify not on main - if on main branch, stop and inform the user.
-
Push the branch if needed:
git push -u origin $(git branch --show-current) -
Create or find PR:
- If no PR exists, create one with
--fill-verboseto include commit details:gh pr create --base main --fill-verbose - If PR exists, show its current status with
gh pr view
- If no PR exists, create one with
-
Merge the PR (squash merge, delete branch):
gh pr merge --squash --delete-branch -
Switch to main and pull:
git checkout main && git pull -
Show the result with
git log -1to confirm the merge completed.