gh-pr-merge
Skill2 starsChanged 44 days agoMITView on GitHub
Squash-merge a GitHub pull request, verify the result, and delete its remote source branch unless the user requests retaining it
In this repository22 other files it gives its agents.
- AGENTS.mdAGENTS.md
- changelog-bump-verSkill
- gh-copilot-review-readSkill
- gh-copilot-review-resolveSkill
- gh-copilot-reviewSkill
- gh-cr-submitSkill
- gh-issue-fixSkill
- gh-issueSkill
- gh-protect-default-branchSkill
- gh-pr-reviewSkill
- gh-prSkill
- gh-releaseSkill
- git-branchSkill
- git-commitSkill
- git-pushSkill
- make-changelogSkill
- mir-skills-installSkill
- mir-skills-updateSkill
- python-venvSkill
- save-planSkill
- session-noteSkill
- work-reportSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
20 rules. About 0 are common, 18 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈18
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 14
Check authentication, PR state, required checks, and review requirements
- Distinctive: line 16
Delete the source branch on GitHub after a verified merge unless the user requests retaining it
- Distinctive: line 18
Verify and report the merge result and resulting commit
- Distinctive: line 22
Use when the user asks to merge or squash-merge a GitHub PR.
- Distinctive: line 32
Use the supplied PR URL directly, or resolve a supplied number in the repository identified by the user or current checkout:
- Distinctive: line 41
If already merged, report its existing merge result and stop without another merge or branch cleanup.
- Very specific: line 42
If mergeable is UNKNOWN, refresh once.
- Distinctive: line 44
Check required CI results:
- Distinctive: line 53
If disabled, report it without changing repository settings or substituting another merge method.
- Distinctive: line 57
Use the head SHA captured during the checks:
- Distinctive: line 63
Never omit the head guard to get past a mismatch.
- Very specific: line 65
Leave --delete-branch off the merge command because it can delete local branches too.
- Distinctive: line 70
After the merge attempt, including a timeout or ambiguous error, read the PR state before deciding whether to retry:
- Distinctive: line 77
If still open, report that the merge has not completed and stop without deleting the source branch.
- Distinctive: line 78
If verification fails, report the uncertainty and the exact error instead of claiming success, deleting the branch, or blindly rerunning …
- Distinctive: line 84
Check the source repository's default branch and current remote references:
- Distinctive: line 90
Delete only the verified source branch on GitHub:
- Distinctive: line 94
Use the same endpoint values checked in Step 1.
- Distinctive: line 95
Verify remote absence by repeating the reference query, including after a timeout or ambiguous deletion error:
- Distinctive: line 108
Do not bypass required checks, reviews, merge queues, or execution permissions.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
What I do
- Resolve a PR number, URL, or the current branch's PR
- Check authentication, PR state, required checks, and review requirements
- Squash-merge the verified PR head without bypassing branch protection
- Delete the source branch on GitHub after a verified merge unless the user requests retaining it
- Preserve local branches and uncommitted work
- Verify and report the merge result and resulting commit
When to use me
Use when the user asks to merge or squash-merge a GitHub PR. Squash is the default merge method for this skill. Do not merge merely because the user asks to create, review, or inspect a PR, or asks how merging works.
An explicit request to merge authorizes the merge and subsequent remote source-branch cleanup without another routine confirmation. Honor requests to retain the branch or requests limited to checking readiness. If the user explicitly requests a different merge method, do not silently squash it; explain this skill's scope or follow that request outside this workflow.
1. Resolve the PR
- Confirm GitHub CLI is installed and authenticated:
gh auth status - Use the supplied PR URL directly, or resolve a supplied number in the repository identified by the user or current checkout:
With no number or URL, omit the positional argument to resolve the current branch's PR. If no PR or repository can be resolved unambiguously, ask for the PR number or URL rather than selecting an arbitrary open PR.gh pr view <number-or-url> --json number,url,title,state,isDraft,baseRefName,headRefName,headRefOid,headRepository,headRepositoryOwner,isCrossRepository,mergeable,mergeStateStatus,reviewDecision,statusCheckRollup - Keep the resolved PR URL, full
headRefOid,headRefName, and source repository (headRepositoryOwner.loginandheadRepository.name) before merging; the source repository can be a fork and its metadata may disappear after automatic branch deletion. Retain the GitHub hostname from the PR URL for API calls. Briefly identify the PR, its base branch, the squash strategy, and planned remote branch cleanup (or the user's retention request). Local uncommitted work is not included in a server-side merge; do not commit or push it as part of this skill.
2. Check Merge Requirements
- If already merged, report its existing merge result and stop without another merge or branch cleanup. If closed without merging or still a draft, report the state; do not reopen it or mark it ready automatically.
- If
mergeableisUNKNOWN, refresh once; if still unknown, report that GitHub has not finished computing mergeability. Stop for conflicts rather than modifying the PR's code or history. - Inspect the review decision and merge state. Stop for missing required reviews, requested changes, or unmet branch requirements; do not use
--adminor weaken repository protections. - Check required CI results:
Failing or pending required checks block an immediate merge. Exit codegh pr checks <pr-url> --required8means checks are pending; do not start an indefinite watch or enable--autoimplicitly. A response explicitly stating that no required checks exist is acceptable; authentication, network, and permission errors are not evidence that no checks are required. - Confirm squash merging is enabled for the PR's base repository, using the owner/repository from the resolved PR URL:
If disabled, report it without changing repository settings or substituting another merge method. GitHub remains authoritative about merge eligibility when the merge command runs.gh api repos/<owner>/<repo> --jq '.allow_squash_merge'
3. Squash-Merge
Use the head SHA captured during the checks:
gh pr merge <pr-url> --squash --match-head-commit <verified-head-sha>- Never omit the head guard to get past a mismatch. If new commits arrive, inspect the new diff and rerun the readiness checks before attempting a merge of the new head; stop if the added changes make the user's intended scope unclear.
- Preserve the PR's current base branch; do not retarget it or push directly to the base branch.
- Leave
--delete-branchoff the merge command because it can delete local branches too. Perform remote-only cleanup in Step 5 after verifying the merge; do not switch branches, delete local branches, or discard local changes. - A repository requiring a merge queue may queue the PR instead of completing the merge immediately. Respect the queue and verify the outcome; do not bypass it with
--admin. Queue processing follows repository policy, so do not promise a particular resulting commit until it is available.
4. Verify the Merge
After the merge attempt, including a timeout or ambiguous error, read the PR state before deciding whether to retry:
gh pr view <pr-url> --json url,state,mergedAt,mergeCommit,baseRefName,autoMergeRequest- Continue to cleanup only when
stateisMERGED. Report the PR URL, base branch, andmergeCommit.oidwhen available. - If still open, report that the merge has not completed and stop without deleting the source branch. Mention queued or scheduled status only when the CLI/API confirms it; an accepted request or zero exit code alone does not prove a merge.
- If verification fails, report the uncertainty and the exact error instead of claiming success, deleting the branch, or blindly rerunning the merge.
5. Delete the Remote Source Branch and Report
Skip cleanup when the user requested retaining the branch. Otherwise, after Step 4 confirms the merge, use the captured source repository and branch, not the current local branch or the base repository of a fork PR. If source metadata is missing or ambiguous, report that cleanup could not be performed instead of guessing.
- Check the source repository's default branch and current remote references:
Substitute the captured values and URL-encode the branch name for the endpoint, including anygh api --hostname <github-host> "repos/<head-owner>/<head-repo>" --jq '.default_branch' gh api --hostname <github-host> "repos/<head-owner>/<head-repo>/git/matching-refs/heads/<url-encoded-head-branch>" --jq '.[] | {ref: .ref, sha: .object.sha}'#or%characters. Compare returned refs against the full, unencodedrefs/heads/<headRefName>: this endpoint also returns branches sharing a prefix, so those are not matches. Never delete the source repository's default branch or the PR's base branch in the same repository. If the exact ref is absent from a successful response, report it as already absent (for example, GitHub auto-deleted it) and skip deletion. If its SHA differs from the verified PR head, preserve the branch and report that it changed after the merge. API/authentication errors do not prove absence; report them and stop cleanup. - Delete only the verified source branch on GitHub:
Use the same endpoint values checked in Step 1. A permission or protection error is a cleanup failure; do not bypass it or substitute a local branch deletion.gh api --hostname <github-host> --method DELETE "repos/<head-owner>/<head-repo>/git/refs/heads/<url-encoded-head-branch>" - Verify remote absence by repeating the reference query, including after a timeout or ambiguous deletion error:
Report cleanup as verified only when this request succeeds and the exact source ref is absent. If the ref still exists or verification fails, report the remaining branch or uncertainty; do not blindly retry deletion.gh api --hostname <github-host> "repos/<head-owner>/<head-repo>/git/matching-refs/heads/<url-encoded-head-branch>" --jq '.[] | {ref: .ref, sha: .object.sha}'
Report merge and cleanup results separately: merged commit plus remote branch deleted, already absent, retained on request, or cleanup skipped/failed with the reason. A cleanup failure does not undo a successful merge; never rerun the merge to retry cleanup. Local branches and uncommitted work remain untouched.
Error Handling
- Missing
gh: reportGitHub CLI not found. Install: https://cli.github.com/. - Authentication failure: report the
gherror and direct the user togh auth loginfor the relevant host; never print credentials. - Missing PR, insufficient permissions, rejected merge, or disabled squash merging: report the cause and leave repository settings unchanged.
- Do not bypass required checks, reviews, merge queues, or execution permissions. Do not manually close linked issues; GitHub handles applicable closing references after merge.
References: gh pr merge, gh pr checks, GitHub Git references API.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

