Agent SkillsReviewStage/stage-cli › rebase-origin-main

rebase-origin-main

GitHub

自动拉取最新主干并变基当前分支,逐提交解决冲突。包含冲突解析原则、CI验证及安全强制推送,确保代码整合无误。

.agents/skills/rebase-origin-main/SKILL.md ReviewStage/stage-cli

Trigger Scenarios

需要将当前分支变基到 origin/main 处理变基过程中的合并冲突

Install

npx skills add ReviewStage/stage-cli --skill rebase-origin-main -g -y
More Options

Non-standard path

npx skills add https://github.com/ReviewStage/stage-cli/tree/main/.agents/skills/rebase-origin-main -g -y

Use without installing

npx skills use ReviewStage/stage-cli@rebase-origin-main

指定 Agent (Claude Code)

npx skills add ReviewStage/stage-cli --skill rebase-origin-main -a claude-code -g -y

安装 repo 全部 skill

npx skills add ReviewStage/stage-cli --all -g -y

预览 repo 内 skill

npx skills add ReviewStage/stage-cli --list

SKILL.md

Frontmatter
{
    "name": "rebase-origin-main",
    "metadata": {
        "internal": true
    },
    "description": "Use when rebasing the current branch onto origin\/main, including resolving merge conflicts along the way"
}

Rebase with origin/main

Overview

Fetches the latest origin/main, rebases the current branch onto it, and resolves every conflict that arises — one commit at a time — until the rebase completes cleanly.

Warning: Rebase Flips ours/theirs

During a rebase, git's labels are inverted from what you expect:

Label Means
HEAD / ours (top of conflict) origin/main — the base being rebased onto
theirs (bottom of conflict) Your commit being replayed

Always resolve conflicts to preserve the intent of your commit while incorporating origin/main's context.

Workflow

1. Fetch & Start

git fetch origin
git rebase origin/main

If the output says Successfully rebased — done. No conflicts.

2. Detect Conflicts

git status

Look for lines with both modified, added by us, deleted by them, etc.

3. Resolve Each Conflicted File

For each conflicted file:

  1. Read the file — find all conflict markers (<<<<<<<, =======, >>>>>>>)
  2. Understand both sides:
    • Above ======= (HEAD) = origin/main's version
    • Below ======= = your commit's change
  3. Resolve by editing the file to the correct merged result — no conflict markers left
  4. Verify no conflict markers remain: grep -En "<<<<<<<|=======|>>>>>>>" <file>
  5. Stage the resolved file: git add <file>

If a conflict is ambiguous — where preserving both sides isn't clear — stop and ask the user before resolving.

4. Continue

After all conflicts in the current commit are staged:

git rebase --continue

Git will either move to the next commit (go back to step 2) or report success.

5. Handle Edge Cases

Situation Command
A commit becomes empty after resolution git rebase --skip
You need to abort entirely git rebase --abort
Binary file conflict Show the user and ask which version to keep

6. Verify

After a clean rebase, confirm the branch looks correct:

git log --oneline origin/main..HEAD

7. Fix CI

After a successful rebase, run the full CI suite locally to catch any breakage introduced by the rebase:

pnpm lint && pnpm typecheck && pnpm test && pnpm build

If anything fails, follow the fixing-ci skill workflow starting from Step 2 (Fix Loop) through Step 3 (Verify All): diagnose each failure, fix the root cause, verify, and commit atomically. Do not proceed to push until all checks pass locally — the push is handled by Step 8 below with --force-with-lease.

8. Push

Force-push with lease (safe force-push — aborts if someone else pushed since your last fetch):

git push --force-with-lease

Conflict Resolution Principles

  • Prefer explicit over clever — when in doubt, keep both changes and adjust for correctness
  • Deletions on main win if you also deleted the same thing (skip your no-op)
  • Your additions win unless they conflict with a semantic change in main (e.g., a rename)
  • Never silently discard either side — if a resolution loses meaningful code, flag it to the user

Common Mistakes

Mistake Fix
Leaving conflict markers in file Grep for <<<<<<< before staging
Staging before fully reading the file Read the full file first
Assuming ours = your branch It's inverted in rebase — ours is origin/main
Continuing without reviewing log Always run git log --oneline origin/main..HEAD after

Version History

  • bbd0b9a Current 2026-07-24 16:05

Same Skill Collection

.agents/skills/deslop-ui/SKILL.md
.agents/skills/fixing-ci/SKILL.md
.agents/skills/fixing-pr-comments/SKILL.md
.agents/skills/iterate-pr/SKILL.md
.agents/skills/linear-issue/SKILL.md
.agents/skills/quality-review/SKILL.md
skills/stage-chapters/SKILL.md
.agents/skills/trade-off/SKILL.md

Metadata

Files
0
Version
eabf305
Hash
9bae81f6
Indexed
2026-07-24 16:05

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 20:08
浙ICP备14020137号-1 $mapa de visitantes$