Skip to content
Back to skills

Merge Pr

ASecurity

Safely merges GitHub pull requests using gh CLI. Use when the user wants to merge a PR, merge a pull request, or complete code review.

  • 2 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 10, 2026
documentationbashgit

Works with

  • cli

Security analysis

A100/100

Scanned September 21, 2026

npx -y skills add sakuro/dotfiles --skill merge-pr --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Merge Pr?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Merge Pr
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sakuro-merge-pr/badge)](https://www.skillsdirectory.com/skills/sakuro-merge-pr)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: merge-pr
description: Safely merges GitHub pull requests using gh CLI. Use when the user wants to merge a PR, merge a pull request, or complete code review.
allowed-tools: [Bash, Read, Grep]
---

# Merge PR Skill

Safely merges GitHub pull requests using the `gh` CLI.

**Announce when using this skill**: "Using merge-pr skill to merge a pull request safely."

## Workflow

### 1. Check status

```bash
gh pr view [PR]
gh pr checks [PR]          # add --watch to wait for CI to finish
```

Confirm before merging:
- All required CI checks pass
- Required approvals are met, with no unresolved change requests
- The PR targets the correct base branch
- You have permission to merge

### 2. Merge

```bash
BRANCH_NAME=$(gh pr view [PR] --json headRepositoryOwner,headRefName -q '.headRepositoryOwner.login + "/" + .headRefName')
gh pr merge [PR] --merge --subject ":inbox_tray: Merge pull request #[PR] from $BRANCH_NAME"
```

- Default strategy is `--merge` (preserves full commit history). Use `--squash` only when the PR has many small/WIP commits to consolidate, `--rebase` only for small PRs where a linear history without a merge commit is wanted.
- Always set `--subject` in the format `:inbox_tray: Merge pull request #[PR] from [BRANCH_NAME]`.
- Never pass `--delete-branch` — branch deletion is controlled by the repository's "Automatically delete head branches" setting, not by this skill.
- Omit `[PR]` in any command above to target the PR of the current branch.
- For auto-merge, add `--auto` and run step 3 once `gh pr view [PR]` shows `MERGED`.

### 3. Update local default branch

```bash
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name)
git checkout "$DEFAULT_BRANCH"
git pull
git branch --merged | grep -v "\*" | grep -v "$DEFAULT_BRANCH" | xargs -n 1 git branch -d  # optional: prune merged local branches
```

## Never merge if

- CI checks are failing
- Unresolved change requests exist
- Required approvals are missing
- You lack merge permission
- The PR targets the wrong base branch

## Recovery

**Merge conflicts** — resolve on the PR branch, then retry step 2:
```bash
gh pr checkout [PR]
git fetch origin
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name)
git merge "origin/$DEFAULT_BRANCH"
# resolve conflicts, then:
git push
```

**Merged the wrong PR**:
```bash
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q .defaultBranchRef.name)
git checkout "$DEFAULT_BRANCH" && git pull
git log                          # find the merge commit hash
git revert -m 1 [MERGE_COMMIT_HASH]
git push
```

## Project-specific conventions

Before defaulting to `--merge`, check `CONTRIBUTING.md` and the repository's branch protection rules for merge-strategy overrides.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.