GenesisTools gt:git-rebaser
Guided git rebase cascade for branch hierarchies. Use when rebasing a parent feature branch onto master/main and then updating child branches. Triggers on "rebase branches", "cascade rebase", "rebase onto master", "update child branches after rebase", "rebase feature branch hierarchy", "git rebaser". Handles reflog lookup, --onto mechanics, commit reporting, and user confirmation before any destructive action.
git clone https://github.com/genesiscz/GenesisTools
T=$(mktemp -d) && git clone --depth=1 https://github.com/genesiscz/GenesisTools "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/genesis-tools/skills/git-rebaser" ~/.claude/skills/genesiscz-genesistools-gt-git-rebaser && rm -rf "$T"
plugins/genesis-tools/skills/git-rebaser/SKILL.mdGit Rebaser — Guided Cascade Rebase
Safely rebase a parent branch onto a target (e.g. master) and cascade all child branches using
git rebase --onto. Every destructive step requires explicit user confirmation.
Workflow
Phase 1: Gather Information
Ask the user these questions (use AskUserQuestion sequentially):
- Target branch — "Which branch are you rebasing onto?" (default:
)master - Parent branch — "Which is the parent feature branch to rebase?" (e.g.
)feat/main - Has the parent already been rebased? — "Have you already rebased the parent branch, or should I do it now?"
- Child branches — "List the child branches (comma-separated or space-separated)." (e.g.
)feat/small-1, feat/small-2
Phase 2: Analyze Current State
Run these commands and report results to the user before any action:
# For each branch, show its commit log relative to the parent git log --oneline <parent>..<child> # unique commits per child git log --oneline <target>..<parent> # commits on parent not yet on target git merge-base <parent> <target> # current fork point
Display a clear summary:
Parent branch: feat/main (15 commits ahead of master) Child branches: feat/small-1: 3 unique commits on top of feat/main feat/small-2: 5 unique commits on top of feat/main
Phase 3: Rebase Parent (if not already done)
If the parent has NOT been rebased yet:
- Save the pre-rebase ref:
OLD_PARENT=$(git rev-parse <parent>) - Show the plan: "I will rebase
onto<parent>
. This replays N commits."<target> - Ask confirmation via AskUserQuestion: "Proceed with rebasing <parent> onto <target>?"
- Execute:
git checkout <parent> git rebase <target> - If conflicts occur, stop and tell the user — do NOT attempt to resolve automatically. Guide them through
after they fix conflicts.git rebase --continue
If the parent was ALREADY rebased, determine
OLD_PARENT using this tiered approach:
Tier 1 — Reflog (most reliable, available ~90 days):
- Run
and find the entry just before the rebase (typicallygit reflog <parent>
).<parent>@{1} - Show the user the ref and its commit message. Ask them to confirm it's the pre-rebase tip.
- If confirmed, set
to that ref.OLD_PARENT
Tier 2 —
(works if commits weren't squashed/reordered during rebase):git cherry
If reflog is unavailable or inconclusive:
- Explain to the user: "Reflog doesn't have the old ref. I'll try matching commits by their diff content using
. This works as long as the parent's commits weren't squashed or reordered during the rebase."git cherry - For each child, run:
git cherry -v <parent> <child>- Lines starting with
= commits whose patch content already exists on the new parent (shared commits, safe to exclude).- - Lines starting with
= commits unique to the child (these are the ones to replay).+
- Lines starting with
- Show the user both lists and explain which commits will be kept vs dropped.
- If the
list looks correct, count N unique commits and set+
toOLD_PARENT
.<child>~N
Tier 3 — Interactive commit selection (last resort, always works):
If reflog is gone AND commits were squashed/dropped/reordered (making
git cherry unreliable):
- Explain to the user: "The parent branch's commits were modified during rebase (squashed, dropped, or reordered), so I can't automatically determine which commits belong to the child branch vs the old parent. The only safe approach is for you to identify your commits manually."
- Show the full commit history:
git log --oneline <target>..<child> - Explain: "These are ALL commits on
that aren't on<child>
. Some of these were on the old parent branch (and have already been rebased as part of the new parent). I need you to tell me which commits are YOUR work on this child branch."<target> - Ask the user to identify their commits (by hash, range, or count from the top).
- Once confirmed, set
toOLD_PARENT
where N is the number of unique commits.<child>~N
Phase 4: Report New Parent State
After rebase (or after identifying OLD_PARENT):
git log --oneline <target>..<parent> # new parent commits
Show: "After rebase,
<parent> has N commits on top of <target>."
Phase 5: Cascade Child Branches
For EACH child branch:
-
Show what will happen:
# These are the commits unique to this child (will be replayed) git log --oneline $OLD_PARENT..<child>Display: "Branch
has N unique commits that will be replayed onto new<child>
:" Then list each commit (hash + message).<parent> -
Ask confirmation via AskUserQuestion: "Rebase
onto new<child>
? (commits listed above)"<parent> -
Execute:
git rebase --onto <parent> $OLD_PARENT <child> -
Report result:
git log --oneline <parent>..<child>Show the new commit list for verification.
-
If conflicts occur, stop and guide the user through resolution.
Phase 6: Final Report
After all branches are rebased, show a complete summary:
Cascade rebase complete! master └── feat/main (15 commits) ├── feat/small-1 (3 commits) └── feat/small-2 (5 commits) All branches verified. No orphaned commits.
Critical Rules
- NEVER force-push without explicit user request — this skill only does local rebases
- ALWAYS show commits before and after each rebase step
- ALWAYS ask confirmation before every
commandgit rebase - STOP on conflicts — guide the user, don't auto-resolve
- Use
for child branches — never plaingit rebase --ontogit rebase - Determine
using tiered fallback: reflog →OLD_PARENT
→ interactive commit selection (see Phase 3)git cherry