# Gh PR merge unstable state needs auto and watch branch deletes

> Gh PR merge unstable state needs auto and watch branch deletes is an open-source agent skill for developer tools. Diagnoses stuck gh pr merge errors and restores deleted PR branches safely. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes
- **Repository:** https://github.com/wan-huiyan/agent-traffic-control
- **GitHub stars:** 5
- **License:** MIT
- **Skill name:** gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes
- **Collection:** https://github.com/wan-huiyan/agent-traffic-control
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

This skill covers a set of gh pr merge failures that look like merge conflicts but are not. It explains how to read the mergeable and mergeStateStatus fields to tell pending checks from real file conflicts, and when to queue a merge with the --auto flag instead of retrying.

It also walks through recovery when a PR was closed because its remote branch was deleted, including restoring the branch from a local copy or from the PR's pull ref, reopening the PR, and marking a draft as ready. A further section covers a draft PR error and recommends gating branch cleanup on a non-null mergedAt value rather than on whether the branch exists.

The workflow is built from gh commands and git push and fetch commands, with no bundled scripts. It expects the GitHub CLI and git to be available and an authenticated session with rights to the repository.

## When your agent uses it

> Diagnose and recover from two adjacent `gh pr merge` failure modes that masquerade as merge conflicts. Use when: (1) `gh pr merge --squash` (or `--merge`) errors with "To have the pull request merged after all the requirements have been met, add the `--auto` flag" AND "Run the following to resolve the merge conflicts locally" even though you just pushed a clean resolution; (2) `gh pr view <N> --json mergeable,mergeStateStatus` returns `MERGEABLE` + `UNSTABLE` rather than `MERGEABLE` + `CLEAN`; (3) you delete the remote branch (`git push origin --delete <branch>`) immediately after `gh pr merge` returns a conflict warning thinking the merge succeeded — and discover the PR has flipped to `CLOSED` rather than `MERGED`. The actual root cause for (1)/(2) is almost always pending CI / branch-protection checks, NOT real merge conflicts; the fix is `--auto` flag so `gh` queues the merge for when checks pass. For (3) — recovery requires restoring the remote branch (`git push -u origin <branch>` from your local copy, O

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes)
- [License: MIT](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes)

## Features

- **Merge state diagnosis:** Reads mergeable and mergeStateStatus values to separate pending checks from real conflicts.
- **Auto-queued merges:** Uses gh pr merge with --auto so GitHub merges once required checks pass.
- **Branch restoration:** Recreates a deleted remote branch at the exact PR head commit so the PR re-links.
- **Draft PR handling:** Marks a draft pull request as ready before attempting a merge.
- **Safe branch cleanup:** Gates remote branch deletion on a recorded merge timestamp instead of branch existence.

## Good for

- Merge a pull request that shows UNSTABLE while CI is still running
- Recover a PR that closed after its head branch was accidentally deleted
- Restore a branch from a PR's pull ref when no local copy exists
- Mark a draft pull request ready and merge it
- Write a cleanup script that deletes branches only after a confirmed merge

## Install

### Claude Code

This skill ships in the `agent-traffic-control` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add wan-huiyan/agent-traffic-control
/plugin install agent-traffic-control@wan-huiyan-agent-traffic-control
```

Or copy only this skill to `~/.claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes" ~/.claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes" ~/.agents/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes" ~/.cursor/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/wan-huiyan/agent-traffic-control.git --path plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes
```

Or copy the folder to `~/.gemini/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
cp -R "$tmp/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes" ~/.copilot/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git
```

Then copy `agent-traffic-control/plugins/agent-traffic-control/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes` into your agent's skills folder as `gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes`. Agents that support SKILL.md read one folder per skill.

## FAQ

### Does Gh PR merge unstable state needs auto and watch branch deletes need any tools installed?

It relies on the GitHub CLI (gh) and git, using commands such as gh pr view, gh pr merge, gh pr reopen, gh pr ready and git push and fetch.

### What does the --auto flag change?

It tells GitHub to wait for branch-protection requirements and merge automatically once they are met, so the merge is queued rather than attempted immediately.

### What should I check before deleting a remote branch after a merge error?

Run gh pr view with the mergedAt field and delete the branch only if mergedAt is not null, because a failed merge can leave the PR open or closed without merging.

### Is Gh PR merge unstable state needs auto and watch branch deletes related to other merge problems?

Yes, it points to a sibling skill for the case where gh pr merge --delete-branch fails locally because main is checked out in a worktree.

### How do I install Gh PR merge unstable state needs auto and watch branch deletes in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes to use it in all your projects, or to .claude/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes in one project. Or install the agent-traffic-control plugin, which includes it: /plugin marketplace add wan-huiyan/agent-traffic-control, then /plugin install agent-traffic-control@wan-huiyan-agent-traffic-control.

### Does Gh PR merge unstable state needs auto and watch branch deletes run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Gh PR merge unstable state needs auto and watch branch deletes?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Gh PR merge unstable state needs auto and watch branch deletes?

The closest alternatives to Gh PR merge unstable state needs auto and watch branch deletes are Gh PR merge worktree checkout trap, Merge PR, Gha PR merge ref shows upstream changes, Auto merge rearms while agent live kill then disarm verify and Gh PR pickup designated branch supersede.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Gh PR merge worktree checkout trap](https://ai-powered.com/skills/gh-pr-merge-worktree-checkout-trap): Gh PR merge worktree checkout trap is an open-source agent skill for developer tools.
- [Merge PR](https://ai-powered.com/skills/merge-pr): Merge PR is an open-source agent skill for developer tools.
- [Gha PR merge ref shows upstream changes](https://ai-powered.com/skills/gha-pr-merge-ref-shows-upstream-changes): Gha PR merge ref shows upstream changes is an open-source agent skill for developer tools.
- [Auto merge rearms while agent live kill then disarm verify](https://ai-powered.com/skills/auto-merge-rearms-while-agent-live-kill-then-disarm-verify): Auto merge rearms while agent live kill then disarm verify is an open-source agent skill for developer tools.
- [Gh PR pickup designated branch supersede](https://ai-powered.com/skills/gh-pr-pickup-designated-branch-supersede): Gh PR pickup designated branch supersede is an open-source agent skill for developer tools.
- [Resolve merge conflicts](https://ai-powered.com/skills/resolve-merge-conflicts): Resolve merge conflicts is an open-source agent skill for developer tools.
- [Git post merge cleanup](https://ai-powered.com/skills/git-post-merge-cleanup): Git post merge cleanup is an open-source agent skill for developer tools.
- [Make PR](https://ai-powered.com/skills/make-pr): Make PR is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes
