# Merge Pr

> Merge a GitHub PR via squash after /preparepr. Use when asked to merge a ready PR. Do not push to main or modify code. Ensure the PR ends in MERGED state and clean up worktrees after success.

- Skill: `jiayaoqijia/merge-pr-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx get-skill add jiayaoqijia/merge-pr-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jiayaoqijia/merge-pr-2/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jiayaoqijia (https://skillmd.com/u/jiayaoqijia)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/jiayaoqijia/merge-pr-2

---


# Merge PR

## Overview

Merge a prepared PR via `gh pr merge --squash` and clean up the worktree after success.

## Inputs

- Ask for PR number or URL.
- If missing, auto-detect from conversation.
- If ambiguous, ask.

## Safety

- Use `gh pr merge --squash` as the only path to `main`.
- Do not run `git push` at all during merge.

## Execution Rule

- Execute the workflow. Do not stop after printing the TODO checklist.
- If delegating, require the delegate to run commands and capture outputs.

## Completion Criteria

- Ensure `gh pr merge` succeeds.
- Ensure PR state is `MERGED`, never `CLOSED`.
- Record the merge SHA.
- Run cleanup only after merge success.

## First: Create a TODO Checklist

Create a checklist of all merge steps, print it, then continue and execute the commands.

## Setup: Use a Worktree

Use an isolated worktree for all merge work.

```sh
git rev-parse --show-toplevel
WORKTREE_DIR=".worktrees/pr-<PR>"
```

Run all commands inside the worktree directory.

## Load Local Artifacts (Mandatory)

Expect these files from earlier steps:

- `.local/review.md` from `/reviewpr`
- `.local/prep.md` from `/preparepr`

## Steps

1. Identify PR meta
2. Run sanity checks (not draft, checks passing, not behind main)
3. Merge PR and delete branch (`gh pr merge <PR> --squash --delete-branch`)
4. Get merge SHA
5. Optional comment thanking contributor
6. Verify PR state is MERGED
7. Clean up worktree only on success

## Guardrails

- Worktree only.
- Do not close PRs.
- End in MERGED state.
- Clean up only after merge success.
- Never push to main. Use `gh pr merge --squash` only.
- Do not run `git push` at all in this command.

