ワンクリックで
rebase
Rebase a branch onto main (or a target) with squash-first strategy, semantic merge verification, and safe force-push.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Rebase a branch onto main (or a target) with squash-first strategy, semantic merge verification, and safe force-push.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Performs thorough code review on local changes or PRs. Use this skill proactively after implementing code changes to catch issues before commit/push. Also use when reviewing PRs from other engineers.
Generate a portable session handoff document (task, decisions, state, next steps) as a single copy-pasteable markdown block for resuming on another device or terminal.
Create or update AGENTS.md with repo-specific patterns, conventions, commands, and gotchas for LLM coding agents. Use after implementing features that introduce new patterns worth documenting.
Continues after a session crash while working on a task
Get multi-model perspectives (Codex + Gemini) on any work product. Use at any development stage — planning, design, implementation, testing — to catch blind spots the primary agent might miss.
Creates or updates PLAN.md based on session - auto-detects create vs update mode
| name | rebase |
| version | 1.1.1 |
| description | Rebase a branch onto main (or a target) with squash-first strategy, semantic merge verification, and safe force-push. |
| allowed-tools | Agent, Bash, Edit, Glob, Grep, Read, Write |
| model | opus |
${ARGS}git rev-parse --show-toplevel 2>/dev/null || echo "NOT_IN_GIT_REPO"git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "NO_BRANCH"sh -c 'ref=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed "s@^refs/remotes/origin/@@"); echo "${ref:-main}"'git rev-list --count HEAD --not --remotes 2>/dev/null || echo "unknown"sh -c 'e=""; [ -f Cargo.toml ] && e="${e:+$e,}rust"; [ -f package.json ] && e="${e:+$e,}node"; [ -f pyproject.toml ] && e="${e:+$e,}python"; [ -f go.mod ] && e="${e:+$e,}go"; echo "${e:-unknown}"'[ -f Justfile ] && echo "just" || { [ -f Makefile ] && echo "make" || echo "none"; }Use project tooling (Justfile/Makefile) first. Fall back to these only when no project recipe exists:
| Ecosystem | Build | Lint | Format | Test | Lock Regen |
|---|---|---|---|---|---|
| Rust | cargo build --workspace | cargo clippy --workspace --all-targets -- -D warnings | cargo fmt --all | cargo test --workspace | cargo update |
| Node | npm run build | npm run lint | npm run format or npx prettier --write . | npm test | npm install |
| Python | uv build or python -m build | ruff check . | ruff format . | pytest | uv lock |
| Go | go build ./... | golangci-lint run | gofmt -w . | go test ./... | go mod tidy |
Shell variables (TARGET, MERGE_BASE) do not persist across Bash tool calls. Re-derive from Context when needed.
Expert git operator performing safe, semantically-correct rebases. The #1 failure mode in rebases is not merge conflicts — it is silent semantic breakage after a "clean" auto-merge. Your primary job is to prevent that.
If "Project root" is "NOT_IN_GIT_REPO" or "Current branch" is "NO_BRANCH" or "HEAD" — stop and inform user.
Resolve target branch from ${ARGS}:
| Args | Action |
|---|---|
| Empty | Rebase onto the default base from Context |
Branch name (e.g. main, upstream/main) | Rebase onto origin/<branch> (fetch ensures it's current) |
PR URL (https://github.com/.../pull/123) | gh pr view <number> --json baseRefName to extract base, rebase onto origin/<base> |
Important: Always rebase onto the remote tracking ref (origin/<branch>), not the local branch — git fetch origin updates remote refs but not local branches.
For PR URLs, this extracts the PR's base branch (the branch it merges into). To rebase onto another PR's head branch for stacking, provide the branch name directly.
Set TARGET to the resolved target ref. Run git fetch origin to ensure it's current.
Pre-flight checks:
git status --porcelain — if non-empty, ask user: stash (git stash push -m "rebase-skill: pre-rebase stash") or abortls .git/rebase-merge .git/rebase-apply 2>/dev/null — if either exists, run git rebase --abort automatically, report it, and continuegit config rerere.enabled — if true, note it internally and continue (rerere may silently auto-apply prior conflict resolutions; verify Phase 3 output carefully)MERGE_BASE=$(git merge-base HEAD $TARGET)
git log --oneline $MERGE_BASE..HEAD # Our commits
git log --oneline $MERGE_BASE..$TARGET # Commits to rebase over
git diff --name-only $MERGE_BASE..HEAD # Files WE changed
git diff --name-only $MERGE_BASE..$TARGET # Files THEY changed
Compute: COMMIT_COUNT (our commits), BEHIND_COUNT (their commits), OUR_BRANCH_FILES (files we changed), THEIR_FILES (files they changed), OVERLAP_FILES (intersection of both).
If OVERLAP_FILES is empty and BEHIND_COUNT is small (< 20): skip Phase 1c (structural risk analysis) and Phase 4b (verification subagents). Proceed with a direct rebase followed by build/test verification only.
For each file in OVERLAP_FILES:
Generated files (never manually merge — accept TARGET's version, regenerate after):
Cargo.lock, package-lock.json, yarn.lock, pnpm-lock.yaml, uv.lock, go.sum*.schema.json, openapi.json, openapi.yaml, acp-schema.json, acp-meta.json// This file is auto-generated, // DO NOT EDIT, /* auto-generated */, or living in directories named generated/*.pb.rs, *.pb.go, *_grpc.rsauto-generated, DO NOT EDIT, or @generated; any *.lock* file; any file in a directory named generated/, dist/, or build/Hand-written files — everything else.
Launch ONE Explore subagent to analyze commits from MERGE_BASE to TARGET (substitute actual SHA/ref values — subagents cannot access shell variables):
Analyze commits from <MERGE_BASE_SHA> to <TARGET_REF> in <project root>.
Focus on commits touching OUR_BRANCH_FILES or structural files (Cargo.toml, package.json, tsconfig.json, mod.rs, __init__.py, index.ts, lib.rs).
Check for: file renames/moves (--diff-filter=R), file→directory transitions, crate/package renames or splits, type/API renames, namespace changes, function signature changes.
Output a RISK MATRIX:
FILE | RISK_TYPE | WHAT_CHANGED | IMPACT_ON_OUR_CODE | CONFIDENCE
Present to user: TARGET, commit counts, overlapping files (generated vs hand-written), structural risks from the risk matrix. Proceed immediately.
Persist the risk matrix in full — it's referenced in Phases 3 and 4.
Always squash when COMMIT_COUNT > 1. If COMMIT_COUNT is 1, skip to Phase 2b.
Compute MERGE_BASE=$(git merge-base HEAD $TARGET). Read the branch's commit messages (git log --reverse --format="%s%n%b" $MERGE_BASE..HEAD), compose a single commit message following the repo's conventions (check git log -5 --oneline for style). Write to a temp file for shell safety.
git reset --soft $MERGE_BASE
git commit -F <message-file>
Run git rebase $TARGET.
Check git status for conflicts after each rebase step.
Generated files — accept TARGET's version: git checkout $TARGET -- <file> then git add <file>.
Hand-written files — read conflict markers, consult the risk matrix, use TARGET's new names/paths for renamed types or moved modules, preserve both sides' functional changes.
When ambiguous — use best judgment based on the risk matrix, preserving both sides' functional intent. If a conflict is truly unresolvable (no clear correct answer exists), run git rebase --abort, report the specific conflicting file and context in the final summary, and exit.
After resolving all files: git add <resolved files> && git rebase --continue
Use GIT_EDITOR=true git rebase --continue to prevent editor prompts in the agent context.
If another conflict round occurs, repeat. If rebase aborts unexpectedly: git rebase --abort, report the failure and repo state in the final summary, and exit.
A clean rebase is NOT a correct rebase. This is the critical differentiator.
Run git diff --name-only $TARGET..HEAD. Every one of these files must be verified — not just the ones that conflicted.
Only launch agents for risk categories from the Phase 1 risk matrix. Load the briefing from references/semantic-verification-template.md in this skill's directory. Launch all applicable agents in a single response:
Skip if risk matrix was empty.
For each finding: read the file, apply the correction, git add.
Use project tooling. Check Justfile/Makefile first for a build target. Fall back to the Ecosystem Defaults table above.
If build fails: read error, fix, re-run. Repeat until clean.
If any lockfile was accepted from TARGET in Phase 3, regenerate it using the package manager (see Ecosystem Defaults table — Lock Regen column). This restores the branch's dependencies that were lost when accepting TARGET's lockfile.
Check project tooling (just/make/package.json scripts/CI workflows) for targets containing: generate, gen, schema, codegen, or types. Run each using project tooling recipes, not bare commands — recipes often add required feature flags or environment variables.
After each generator: git add the regenerated files.
Use project tooling or Ecosystem Defaults table above.
Stage only regenerated/formatted/fixed files (not git add -A). Runs unconditionally to capture Phase 4c changes.
git add <changed-files>
git commit --amend --no-edit
Run build using project tooling or Ecosystem Defaults. This catches compile errors from regeneration before running tests.
Run via project tooling, fall back to ecosystem default (cargo test, npm test, pytest, go test ./...).
Build, tests, and lint are independent and can be launched as parallel Bash calls for speed.
If tests fail: determine if it's a regression from our rebase (fix it) or pre-existing (note it, don't fix). Fix regressions, amend, re-test.
One more lint run after regeneration and amendments.
Notable Rust pattern: needless_borrow after rebase often means a function changed from returning T to &T. Our &var creates &&T — remove the extra &.
Fix all lint errors.
Run git push --force-with-lease origin HEAD. Never --force. If lease fails, report it in the summary and stop — do NOT retry with --force. Present completion summary: branch, target, files changed, verification results (build/lint/tests/semantic checks/regenerated files), push result.
If stash was created in Phase 0: git stash pop to restore working changes.
--force-with-lease, never --force. Prevents clobbering others' pushes.On abort: git rebase --abort if in progress, git stash pop the named stash if created in Phase 0, report phase reached and repo state.