Cascade Rebase
Rebase a chain of compound feature branches when the base (main) is updated.
Usage
- •
/cascade-rebase <branch1> <branch2> ...- Rebase branches in order - •
/cascade-rebase- Will prompt for branch chain
Instructions
- •
Get branch chain:
- •If
$ARGUMENTSprovided, parse as space-separated branch names - •Otherwise, ask: "List your branches in order from closest to main to furthest (e.g.,
feature/phase1 feature/phase2 feature/phase3)"
- •If
- •
Fetch and validate:
bashgit fetch origin main <all-branches>
Verify all branches exist.
- •
Record current commit hashes (needed for
--onto):bashgit rev-parse origin/<branch>
Store as
old_hash_<branch>for each branch. - •
Rebase first branch onto main:
bashgit checkout <branch1> git rebase origin/main
Record new hash:
new_hash_<branch1>=$(git rev-parse HEAD) - •
Cascade to subsequent branches: For each remaining branch:
bashgit checkout <branchN> git rebase --onto <new_hash_prev> <old_hash_prev> <branchN>
Record:
new_hash_<branchN>=$(git rev-parse HEAD)The
--ontosyntax:- •
<new_hash_prev>: Where to attach (tip of rebased previous branch) - •
<old_hash_prev>: Old parent to detach from - •
<branchN>: Current branch being rebased
- •
- •
Handle conflicts:
- •If rebase conflicts occur, pause and help resolve
- •After resolution:
git rebase --continue - •User can abort:
git rebase --abort
- •
Push all branches: Ask user: "Rebase complete. Push all branches with --force-with-lease?"
bashgit push origin <branch1> --force-with-lease git push origin <branch2> --force-with-lease # ... etc
- •
Summary: Show old → new commit hashes for each branch.
Example
code
Cascade rebase: main → feature/phase1 → feature/phase2 → feature/phase3 Step 1: Rebasing feature/phase1 onto main... Done: abc123 → def456 Step 2: Rebasing feature/phase2 onto feature/phase1... Done: 111aaa → 222bbb Step 3: Rebasing feature/phase3 onto feature/phase2... Done: 333ccc → 444ddd All branches rebased. Ready to push.
Important Notes
- •This rewrites history - ensure no one else is working on these branches
- •Always use
--force-with-lease(not--force) for safety - •If conflicts occur mid-chain, resolve before continuing