merge-pr-sync-main
Safely merge GitHub PRs and update local main branches while ensuring history consistency.
Install
mkdir -p .claude/skills/merge-pr-sync-main && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10204" && unzip -o skill.zip -d .claude/skills/merge-pr-sync-main && rm skill.zipInstalls to .claude/skills/merge-pr-sync-main
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Use when a staged PR is ready for remote main and local main sync. Keywords: merge PR, sync main, PR合并, 同步main, 阶段PR收尾, Stage PR, worktree cleanup.Key capabilities
- →Merge remote PRs
- →Sync local main branch
- →Verify CI status
- →Cleanup worktrees
How it works
It verifies PR status and CI checks, merges via GitHub, and fast-forwards the local main branch to match remote.
Inputs & outputs
When to use merge-pr-sync-main
- →Sync local main after a PR is merged
- →Verify CI status before closing a PR
- →Safely merge a feature branch into production
- →Cleanup local worktree after remote sync
About this skill
Merge PR and Sync Main
Overview
Safely finish a staged PR by merging it through GitHub, then fast-forwarding local main to origin/main. Prefer the PR surface over local merges so local history matches the repository's protected-branch workflow.
When to Use
Use this when:
- a stage branch has already been pushed;
- a GitHub PR exists;
- CI/review is expected to be green;
- the user wants the PR merged into remote
mainand localmainupdated.
Do not use this for unpushed work, failing PRs, draft PRs, or branches with unclear base history.
Safety Rules
- Never merge if checks are failing or pending.
- Never merge a draft PR unless the user explicitly asks.
- Never overwrite local changes.
- Never use
git reset --hardautomatically. - Prefer
gh pr mergeover localgit mergeintomain. - Sync local
mainwithgit pull --ff-only origin main. - Keep feature worktrees by default until the PR is merged and no follow-up fixes are needed.
Workflow
1. Inspect PR and Worktree
Run from the stage worktree or repository root:
git status --short --branch
gh pr view <PR_NUMBER_OR_BRANCH> --json number,url,state,isDraft,baseRefName,headRefName,title,mergeStateStatus,statusCheckRollup
gh pr checks <PR_NUMBER_OR_BRANCH>
Continue only if:
- PR is
OPEN; isDraftisfalse;baseRefNameismain;mergeStateStatusis clean/mergeable;- checks are successful, with only intentional skips allowed;
- worktree is clean.
2. Merge Remote PR
Use the repository's normal merge strategy. For this repository, use merge commits unless the user or repository policy says otherwise:
gh pr merge <PR_NUMBER> --merge
If GitHub refuses because the branch is stale or conflicted, stop and report the reason.
3. Sync Local Main
After merge succeeds:
git fetch origin --prune
git switch main
git pull --ff-only origin main
Verify:
git status --short --branch
git log --oneline --decorate -5
Expected: local main is clean and aligned with origin/main.
4. Optional Cleanup
Only clean up when the user asks or when the next workflow explicitly needs it.
git worktree list
git worktree remove <WORKTREE_PATH>
git branch --merged main
git branch -d <FEATURE_BRANCH>
Delete the remote branch only with explicit user approval:
git push origin --delete <FEATURE_BRANCH>
Failure Handling
Checks Failed
Stop. Report failing checks and do not merge.
Local Main Cannot Fast-Forward
Stop. Report that manual inspection is required. Do not reset automatically.
Worktree Has Local Changes
Stop. Report changed files. Ask whether to commit, stash, or discard.
Report Format
完成:
- PR #<number> 已合并到远程 main
- 本地 main 已通过 git pull --ff-only 同步到 origin/main
- 当前 main 最新提交:<short-sha> <subject>
- 工作区状态:clean
验证:
- gh pr checks <PR>
- git status --short --branch
- git log --oneline --decorate -5
后续:
- 可以从最新 main 创建下一阶段分支
When not to use it
- →When checks are failing
- →When the PR is a draft
- →When the branch history is unclear
Prerequisites
Limitations
- →Requires clean worktree
- →Cannot merge failing PRs
How it compares
It enforces a safe, PR-centric merge workflow that keeps local history aligned with protected branches.
Compared to similar skills
merge-pr-sync-main side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| merge-pr-sync-main (this skill) | 0 | 2mo | Review | Intermediate |
| github-workflow-automation | 11 | 2mo | Review | Advanced |
| testing-workflow | 16 | 9mo | Review | Intermediate |
| github-actions-templates | 7 | 3mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
github-workflow-automation
ruvnet
Advanced GitHub Actions workflow automation with AI swarm coordination, intelligent CI/CD pipelines, and comprehensive repository management
testing-workflow
amo-tech-ai
Comprehensive testing workflow for E2E, integration, and unit tests. Use when testing applications layer-by-layer, validating user journeys, or running test suites.
github-actions-templates
wshobson
Create production-ready GitHub Actions workflows for automated testing, building, and deploying applications. Use when setting up CI/CD with GitHub Actions, automating development workflows, or creating reusable workflow templates.
glab
NikiforovAll
Expert guidance for using the GitLab CLI (glab) to manage GitLab issues, merge requests, CI/CD pipelines, repositories, and other GitLab operations from the command line. Use this skill when the user needs to interact with GitLab resources or perform GitLab workflows.
create-pr
n8n-io
Creates GitHub pull requests with properly formatted titles that pass the check-pr-title CI validation. Use when creating PRs, submitting changes for review, or when the user says /pr or asks to create a pull request.
gh-fix-ci
openai
Use when a user asks to debug or fix failing GitHub PR checks that run in GitHub Actions; use `gh` to inspect checks and logs, summarize failure context, draft a fix plan, and implement only after explicit approval. Treat external providers (for example Buildkite) as out of scope and report only the details URL.