| name | merge |
| allowed-tools | Bash(git add:*), Bash(git commit:*), Bash(git checkout:*), Bash(git pull:*), Bash(git push:*), Bash(git branch:*), Bash(git fetch:*), Bash(git log:*), Bash(git diff:*), Bash(git reset:*), Bash(git rebase:*), mcp__plugin_github_github__list_pull_requests, mcp__plugin_github_github__create_pull_request, mcp__plugin_github_github__update_pull_request, mcp__plugin_github_github__merge_pull_request |
| description | Use when the user wants to merge the current branch to master — merges via GitHub PR |
| tags | ["pr"] |
Context
- Current branch: !
git branch --show-current 2>/dev/null || echo '(not in a git repo)'
- Git status: !
git status --short 2>/dev/null || echo '(not in a git repo)'
- Remotes: !
git remote -v 2>/dev/null | head -10
- Commits (upstream): !
git log upstream/master..HEAD --oneline 2>/dev/null | head -50
- Commits (origin): !
git log origin/master..HEAD --oneline 2>/dev/null | head -50
- Diff stat (upstream): !
git diff upstream/master..HEAD --stat 2>/dev/null | head -50
- Diff stat (origin): !
git diff origin/master..HEAD --stat 2>/dev/null | head -50
Your task
Merge the current branch into master via GitHub PR merge. This preserves PR association so the commit on master links back to the PR.
Important: An existing open PR is NOT required. If no PR exists, one will be created. If there are uncommitted changes, they will be committed first. The only requirement is that the branch has something to merge (commits diverging from master).
-
Determine the target remote (CRITICAL -- use this for all subsequent steps):
- Check which remotes exist using
git remote
- If an
upstream remote exists, set TARGET=upstream
- Otherwise, set TARGET=origin
- All references to
{TARGET} below must use the determined remote
-
Commit any uncommitted changes:
- If there are uncommitted changes, stage and commit them with an appropriate message
-
Store the current branch name:
- Save the current branch name for the merge
-
Analyze all commits and changes:
- Review ALL commits on the branch since it diverged from
{TARGET}/master
- If there are no prior commits (only the changes just committed in step 1), base the summary on that commit
- Review the full diff to understand what the branch accomplishes
- Determine a clear, concise summary for the squashed commit based on the overall purpose
-
Rebase on {TARGET}/master:
- Run
git fetch {TARGET}
- Run
git rebase {TARGET}/master
- If there are conflicts, resolve them and continue the rebase
-
Force-push the rebased branch to {TARGET}:
- Run
git push {TARGET} <branch-name> --force-with-lease
-
Ensure a PR exists with a good title and description:
- Craft a PR title and body based on your analysis from step 3:
- Title: concise imperative summary of what the branch accomplishes (not individual commits)
- Body: a short description of the changes, followed by
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use
mcp__plugin_github_github__list_pull_requests (with head set to <owner>:<branch>, state: "open") to check if a PR already exists
- If a PR exists, update it with
mcp__plugin_github_github__update_pull_request (set title and body)
- If no PR exists, create one with
mcp__plugin_github_github__create_pull_request (base: master)
-
Squash merge via GitHub:
- Use the same title and body from step 6 as the squash commit message
- Use
mcp__plugin_github_github__merge_pull_request with merge_method: "squash" and the title/body as commit message
- If squash is not allowed, fall back to
mcp__plugin_github_github__merge_pull_request with merge_method: "rebase"
- This merges through GitHub so the PR shows as "Merged" and the commit links to the PR
-
Update local master:
- Run
git checkout master
- Run
git pull {TARGET} master
-
Report the result:
- Confirm the merge was successful
- Show the PR URL (so the user can verify the "Merged" status)
- Show the final commit on master
Execute all steps in sequence. If any step fails, stop and report the error.