用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/drn/dots --skill merge命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | merge |
| allowed-tools | Bash(git add:*), Bash(git commit:*), Bash(git log:*), Bash(git diff:*), Bash(git status:*), Bash(git rebase:*), Bash(git checkout:*), Bash(git reset:*), Bash(bash ~/.claude/skills/merge/scripts/merge.sh:*), Bash(bash agents/skills/merge/scripts/merge.sh:*) |
| description | Merge current branch to the default branch via GitHub PR merge. Use when ready to merge a PR or land a branch. |
git branch --show-currentgit status --shortgit remote -v 2>/dev/null | head -10git branch -r 2>/dev/null | grep -oE 'origin/(main|master)' | head -1git log upstream/main..HEAD --oneline 2>/dev/null | head -50git log upstream/master..HEAD --oneline 2>/dev/null | head -50git log origin/main..HEAD --oneline 2>/dev/null | head -50git log origin/master..HEAD --oneline 2>/dev/null | head -50git diff upstream/main...HEAD --stat 2>/dev/null | head -50git diff upstream/master...HEAD --stat 2>/dev/null | head -50git diff origin/main...HEAD --stat 2>/dev/null | head -50git diff origin/master...HEAD --stat 2>/dev/null | head -50This skill participates in a phase chain. Read ~/.claude/skills/_shared/resources/phase-protocol.md for the full protocol.
Before merging: Read the latest .context/phases/ship-*.md for the PR number/URL if available.
After merge completes: Write a land-{ts}.md artifact to .context/phases/ (create with mkdir -p .context/phases). The Detail section should include the merge commit SHA and PR URL. Optionally archive all phase artifacts: mkdir -p .context/phases/archive && mv .context/phases/*.md .context/phases/archive/.
Merge the current branch into the default branch via GitHub PR merge. An existing PR is NOT required — one will be created if needed.
Before committing anything, verify the branch is in a mergeable state.
Run:
TARGET=$(git remote | grep -q '^upstream$' && echo upstream || echo origin)
git fetch "$TARGET" >/dev/null 2>&1 || true
DEFAULT_BRANCH=$(git branch -r 2>/dev/null | grep -oE "${TARGET}/(main|master)" | head -1 | sed "s|${TARGET}/||")
[ -z "$DEFAULT_BRANCH" ] && DEFAULT_BRANCH="master"
AHEAD=$(git log "$TARGET/$DEFAULT_BRANCH..HEAD" --oneline 2>/dev/null | wc -l | tr -d ' ')
BEHIND=$(git log "HEAD..$TARGET/$DEFAULT_BRANCH" --oneline 2>/dev/null | wc -l | tr -d ' ')
DIRTY=$(git status --short 2>/dev/null | wc -l | tr -d ' ')
echo "ahead=$AHEAD behind=$BEHIND dirty=$DIRTY default_branch=$DEFAULT_BRANCH"
Decide based on the output:
These ahead/behind counts are the authoritative signal for what the branch will land. The injected context block reflects them: the "Commits vs <base>" lines use a two-dot range (<base>..HEAD), which lists exactly the commits this branch adds, and the "Diff stat vs <base> (branch-only)" lines use a three-dot diff (<base>...HEAD, from the merge-base), which shows only this branch's own file changes even when behind > 0. Both are already scoped to the branch — neither inflates when behind.
Caveat for manual checks: if you run a plain two-dot diff yourself (git diff <base>..HEAD --stat) while the branch is behind, it folds base-ahead history in as inverted changes and lists many files unrelated to this branch. That is expected, not a problem with the branch — Step 3 rebases the branch onto the current <base> tip, after which the two-dot and three-dot diffs converge. Trust the Step 0 counts and the three-dot diff stat above, not a raw two-dot diff.
If git status shows uncommitted changes, stage and commit them with an appropriate message. Skip if working tree is clean.
Review all commits and the full diff since the branch diverged from the default branch. Determine:
If there are no prior commits (only what was committed in step 1), base the summary on that commit.
Resolve the script path — use the first that exists:
~/.claude/skills/merge/scripts/merge.sh (deployed via symlink)agents/skills/merge/scripts/merge.sh (repo-relative, for development/workspaces)bash <script-path> [--method <squash|merge|rebase>] [--keep-branch] "<title>" "<body>"
The script defaults to squash (collapses all commits into one). Pick a different method when squash would lose intentional structure:
--method squash (default) — single commit, ideal for a stream of WIP commits.--method merge (alias --merge) — preserves all commits via a merge commit. Use when each commit is independently meaningful and you want to keep the merge boundary visible on master.--method rebase (alias --rebase) — preserves all commits linearly via fast-forward / rebase. Use this when the user has deliberately split work into multiple commits (e.g., the user ran /squash to condense 7 commits into 2 separate logical commits, and wants both on master). A naive squash merge here would silently undo that intent.Heuristic: if the branch has more than one commit AND the commit messages look distinct rather than incremental ("WIP", "fix typo"), confirm with the user before using the default squash. The deliberate-split case is common after /squash.
After a successful squash merge, the script auto-switches the current worktree to the default branch (master/main). This prevents the next agent or follow-up task in this worktree from committing against the now-divergent feature branch — squash collapses all commits into one new commit on master, so the old feature branch HEAD no longer shares history with the merged result.
--method merge / --method rebase — auto-switch is off by default. Both methods preserve the original commits, so the feature branch may still be useful for stacked PRs or chained follow-on work.--keep-branch — opt out of auto-switch on squash. The worktree stays on the feature branch and the script prints a divergence warning instead. Use this for stacked-PR workflows that squash but still need to keep the branch checked out (rare).If auto-switch fails (e.g., uncommitted changes in the worktree, or master is checked out in another worktree), the script falls back to a loud warning rather than aborting — the merge itself already succeeded.
--admin escalationThe script handles branch protection on its own — you do not need to fall back to a manual gh pr merge --admin. When reviewDecision is REVIEW_REQUIRED or CHANGES_REQUESTED, do_merge escalates through tiers automatically:
--admin (branch-protection bypass; succeeds when you hold admin on the repo). A successful admin merge prints WARNING: merged via --admin (branch protection bypassed) so the bypass is never silent.--admin fails (lacking admin is one cause, but a pending required status check is the more common one — gh refuses an admin merge until required checks resolve), enable --auto (auto-merge) so the PR lands once checks pass. The real admin error is printed (Admin merge failed: …), not swallowed.exit 4 — and the exit-4 message includes the actual admin-merge error so the cause is visible.On a repo where you hold admin, /merge lands the PR through the review gate itself — never substitute a raw gh pr merge --admin, which skips the post-squash worktree auto-switch and strands you on the merged feature branch. A plain non-blocked PR merges directly; the admin tier only kicks in when review is actually blocking.
Exit 0 — Show the output block verbatim as your final response. Do not add commentary.
Exit 2 (rebase conflict) — Resolve conflicts:
git add resolved filesgit rebase --continuebash <script-path> --skip-rebase [--method <method>] "<title>" "<body>"Special case: "distinct types" conflicts. If the rebase reports conflicts because the branch converted regular files to symlinks (or vice versa) while master independently edited those same files, do NOT naively resolve with --theirs or --ours. Both sides "win" — the branch's symlink target was sourced from old master content, so keeping the branch's version silently loses master's content updates.
Recovery pattern:
git rebase --abort.git rebase -i master and drop it, or git reset --soft <sha-before-symlink-commit> then re-stage selectively).--skip-rebase.Exit 3 — Tell the user: "Nothing to merge — branch has no commits ahead of the default branch."
Exit 4 (review blocked) — Review is required (REVIEW_REQUIRED/CHANGES_REQUESTED) and both the --admin bypass and auto-merge failed. The script prints the actual gh pr merge --admin error (admin merge error: …) alongside the auto-merge error — read it before concluding anything. Do not assume "no admin"; an admin merge fails for several reasons, and a pending required status check is the most common (gh refuses an admin merge until required checks resolve, even for an admin).
Exit 1 — Report the error from stderr.