Merge the open pull request of the branch checked out in this worktree on the user's confirmation, after settling its conflicts with the base and reviewing what changed, and once the checks of the host pass. Use when the user asks to merge the pull request of an issue or of this branch, or a session starts with `/merge-pull-request`.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Merge Pull Request?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/electron-libre-merge-pull-request)
---
name: merge-pull-request
description: Merge the open pull request of the branch checked out in this worktree on the user's confirmation, after settling its conflicts with the base and reviewing what changed, and once the checks of the host pass. Use when the user asks to merge the pull request of an issue or of this branch, or a session starts with `/merge-pull-request`.
---
# Merge a pull request
The argument is an issue stem, a pull request number, or nothing (the current branch). The review of a pull request
is `skill:review-pull-request`'s; this skill reviews only what it changed or did not see. The merge asks for a
permission whatever the mode (the managed `ask` rule on `gh pr merge`): spell it `gh pr merge <number>` as below, never work around it, never pass
`--admin`.
## 1. Check where it runs
Run step 1 of `skill:review-pull-request` (the pull request, the worktree, the clean tree, the commits pulled from
the host); a draft is a stop too. When the host brought commits in, they were not reviewed: run its step 2 before
going on.
## 2. Settle the conflicts
`<upstream>` is the branch the base tracks, `git rev-parse --abbrev-ref <baseRefName>@{upstream}` (`<remote>/<base>`,
whatever the remote is named); when the base tracks nothing here, `<remote>` is the one of the pull request's branch
(`git rev-parse --abbrev-ref @{upstream}`) and `<upstream>` is `<remote>/<baseRefName>`; neither: stop. Push first the local commits the host lacks (`git push`), then read `gh pr view
<number> --json mergeable,headRefOid` (`UNKNOWN` while the host computes it: read it again). A `headRefOid` other than
the local `HEAD` means someone pushed meanwhile: stop.
- `MERGEABLE`: when the feature `review-gate` is on (not in the `disabled` of `[cardinal]` in
`.claude/cardinal.toml`), every commit passed the review gate of the project: **no review**, go to step 3. With it
off, run step 2 of `skill:review-pull-request` first.
- `CONFLICTING`: keep `headRefOid` as `<old head>`, fetch the base alone (`git fetch <remote> <baseRefName>`, which
leaves the remote branch of the pull request as read), then `git rebase <upstream>` and resolve each conflict
yourself, keeping the intent of both sides; never `--skip` a commit. The rebase commits without the review gate: the
review below covers each resolution. A conflict whose intent you cannot tell is a stop: `git rebase --abort` and
report its files. Once rebased, run `cardinal run project-check`, then invoke `/code-review medium <target>` with
`<target>` the line `cardinal run review-target <upstream>` prints; commit its fixes through the review gate as
step 2 of `skill:review-pull-request` says, but push nothing yet. Ask the user through the question tool to replace
the pushed branch (the commits rebased, the conflicts settled, the findings fixed); on their go, `git push
--force-with-lease=<headRefName>:<old head>`, which refuses when someone pushed since: then stop. Only the issue
branch is rewritten, never the base.
## 3. Wait for the checks
Run `gh pr checks <number> --watch` with `run_in_background` and wait for its exit: a watch in the foreground is cut by
the time limit of the Bash tool. It prints `no checks reported` when the repository has none: go on. A failing check:
read its log (`gh run view <run> --log-failed`), fix it in a commit through the review gate, `git push`, and wait
again; one you cannot fix, or that fails outside the change, is a stop with its name and its line.
## 4. Merge on confirmation
Read the methods the repository allows: `gh repo view --json mergeCommitAllowed,squashMergeAllowed,rebaseMergeAllowed`.
Ask the user through the question tool whether to merge pull request `#<number>` (its URL, the checks, what was
settled or reviewed), one option per allowed method (`squash`, `merge`, `rebase`) and one to not merge now. On a
method, run `gh pr merge <number> --<method>`, with no `--delete-branch`: the branch is checked out in this worktree.
When `gh` refuses (a required review, a branch protection), report its line and stop: never retry with `--admin`. On
"not now", stop with the pull request left open.
## 5. Report
A table `step | result` (conflicts settled, review and its findings, commits pushed, checks, merge with its method and
the merged commit of `gh pr view <number> --json mergeCommit`), then what is left: the trunk of the main worktree to
bring up to date with the host, the branch and this worktree to remove once it is (`cardinal run worktree close
<branch>` from the main worktree).