rebase-parent
npx machina-cli add skill flurdy/agent-skills/rebase-parent --openclawRebase onto Updated Parent Branch
Rebase the current branch onto a parent branch that has been updated.
Usage
/rebase-parent
/rebase-parent feature/parent-branch # Explicit parent branch
Instructions
1. Identify Parent Branch
If not provided, try to determine the parent:
# Get current branch
git branch --show-current
# Check PR base branch
gh pr view --json baseRefName --jq '.baseRefName'
If the base is main, this skill doesn't apply - use /rebase-main instead.
Ask the user to confirm the parent branch if uncertain.
2. Check Current State
# Check for uncommitted changes
git status --porcelain
# Get current branch
git branch --show-current
Stash or commit uncommitted changes before proceeding.
3. Fetch Latest Parent
git fetch origin {parent-branch}
4. Find the Fork Point
The tricky part with rebasing onto an updated parent is finding where your branch originally diverged. If the parent was rebased, the old base commits are gone.
# Get the merge base (may be outdated if parent was rebased)
git merge-base HEAD origin/{parent-branch}
# Count commits unique to your branch
git rev-list --count origin/{parent-branch}..HEAD
5. Perform the Rebase
Use --onto to rebase only your commits onto the new parent:
# Find how many commits are yours (after the original fork point)
# Then rebase those commits onto the updated parent
git rebase --onto origin/{parent-branch} $(git merge-base HEAD origin/{parent-branch}) HEAD
If that doesn't work cleanly (merge-base is stale), try:
# Interactive rebase to select only your commits
git rebase -i origin/{parent-branch}
6. Handle Conflicts
If conflicts occur:
- List conflicting files:
git diff --name-only --diff-filter=U - Resolve each conflict
- Stage resolved files:
git add {file} - Continue:
git rebase --continue
If stuck, abort and ask for guidance: git rebase --abort
7. Force Push
git push --force-with-lease
8. Update PR Base (if needed)
If the PR base branch needs updating:
gh pr edit --base {parent-branch}
9. Report Result
Inform the user:
- Successfully rebased X commits onto {parent-branch}
- Conflicts resolved (if any)
- Force pushed to origin
Source
git clone https://github.com/flurdy/agent-skills/blob/main/skills/rebase-parent/SKILL.mdView on GitHub Overview
Rebase your current branch onto a parent branch that has new commits or was rebased, so stacked PRs stay in sync. This helps keep your changes on top of the latest parent after updates or force-pushes.
How This Skill Works
Identify the parent branch (explicitly provided or inferred from the PR base). Fetch the latest parent, determine the old fork point with git merge-base, and rebase your commits onto origin/{parent-branch} using --onto. If conflicts arise, resolve them, continue the rebase, then force-push and optionally update the PR base.
When to Use It
- You have stacked PRs and the parent branch has been updated (rebased or received new commits).
- The parent branch was rebased or force-pushed, and you need to align your branch on top of its new state.
- The PR base is not main; use this instead of the dedicated main-rebase workflow when updating under a non-main parent.
- You want to preserve only your commits on top of the updated parent without re-writing the parent history.
- After a successful rebase, you plan to force-push with --force-with-lease and consider updating the PR base if necessary.
Quick Start
- Step 1: Identify the parent branch (or confirm it is not main) and ensure you have the latest context.
- Step 2: Run the fetch and rebase sequence: git fetch origin {parent-branch} and git rebase --onto origin/{parent-branch} $(git merge-base HEAD origin/{parent-branch}) HEAD
- Step 3: Resolve conflicts if any, then push with --force-with-lease and update the PR base if required.
Best Practices
- Confirm the parent branch name before starting; if uncertain, ask the user or inspect the PR.
- Stash or commit any uncommitted changes to avoid losing work.
- Fetch origin and verify the parent actually changed before rebasing.
- Use the provided --onto merge-base approach; fall back to an interactive rebase if needed.
- Push with --force-with-lease and then update the PR base if required.
Example Use Cases
- Rebase feature/login onto updated parent feature/auth-refactor after the parent received new commits.
- Stacked PRs where the parent was force-pushed; rebase your feature onto origin/{parent-branch} to maintain clean history.
- Parent updated via rebase; rebasing prevents diverged history and keeps the PRs in sync.
- Parent base is not main; a developer uses this skill to align their branch without using rebase-main.
- After resolving conflicts during the rebase, you push with --force-with-lease and refresh the PR base if needed.