From scm-utils
Rebase a feature branch onto its base branch to produce a linear commit history. Use when the user asks to "rebase my branch", "rebase onto main", "rebase PR
npx claudepluginhub nsheaps/ai-mktpl --plugin scm-utilsThis skill is limited to using the following tools:
Rebase a feature branch onto its base branch to produce a clean, linear commit history.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Migrates code, prompts, and API calls from Claude Sonnet 4.0/4.5 or Opus 4.1 to Opus 4.5, updating model strings on Anthropic, AWS, GCP, Azure platforms.
Provides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Rebase a feature branch onto its base branch to produce a clean, linear commit history.
Current branch: !git branch --show-current 2>/dev/null || echo "(not in a git repo)"
Working tree status: !git status --porcelain 2>/dev/null | head -5; COUNT=$(git status --porcelain 2>/dev/null | wc -l); [ "$COUNT" -gt 5 ] && echo "... and $((COUNT - 5)) more" || true
PR info for current branch:
!gh pr view --json baseRefName,headRefName,number,title,state 2>/dev/null || echo "(no PR found or gh not authenticated)"
This skill rebases a feature branch on top of its base branch instead of merging. Use rebase when:
Key difference from update-branch: The update-branch skill uses git merge (preserves history, no force push needed). This skill uses git rebase (rewrites history, requires force push).
Default behavior (no arguments): Use the current directory, get the current branch via git branch --show-current, find the associated PR via gh pr list --head <branch>, and rebase onto the PR's base branch.
Determine the target branch from the provided input. Accept any of:
| Input Type | Example | Resolution |
|---|---|---|
| No input | (empty) | Current directory → current branch → find PR → rebase |
| PR number | 123, #123 | gh pr view 123 --json headRefName,baseRefName |
| PR URL | https://github.com/org/repo/pull/123 | Parse number, use gh pr view |
| Branch name | feature/my-branch | Use directly, find PR with gh pr list --head <branch> |
| Directory | /path/to/repo | cd there, get current branch, find PR |
Critical: Always query the PR to determine the base branch. Never assume main or master.
# Get branch info from PR
gh pr view <number> --json headRefName,baseRefName,number,url
# Find PR for a branch
gh pr list --head <branch-name> --json number,baseRefName --limit 1
Execute these steps in order:
Ensure the working tree is clean before rebasing:
git status --porcelain
If there are uncommitted changes, stop and ask the user whether to stash, commit, or abort. A rebase with a dirty working tree will fail.
git fetch --all --prune
BASE_BRANCH=$(gh pr view <number> --json baseRefName --jq '.baseRefName')
If no PR exists for the branch, ask the user what the base branch should be.
git checkout <feature-branch>
Before rebasing, incorporate any remote changes to the feature branch:
git pull origin <feature-branch> --rebase
git rebase origin/$BASE_BRANCH
If conflicts occur, see Conflict Resolution.
Since rebase rewrites history, a force push is required. Always use --force-with-lease to prevent overwriting others' work:
git push --force-with-lease origin <feature-branch>
NEVER use --force — --force-with-lease will fail safely if the remote has commits you haven't seen.
Confirm the remote branch is updated:
gh pr view <number> --json commits,mergeable,mergeStateStatus
Rebase applies commits one at a time, so conflicts must be resolved per-commit.
When a conflict occurs mid-rebase:
# See which files conflict
git diff --name-only --diff-filter=U
# After resolving conflicts in a file
git add <file>
# Continue the rebase
git rebase --continue
To abort and return to the pre-rebase state:
git rebase --abort
Resolve directly when the conflict is clearly one of:
For conflicts requiring analysis, delegate to specialized agents:
Use Explore agent with haiku model to understand:
Use Plan agent to determine:
Execute the resolution — the executing agent owns the final resolution.
Stage and continue:
git add <resolved-files>
git rebase --continue
Verify the resolution — run tests or builds after the full rebase completes.
For detailed conflict patterns, see the update-branch skill's references/conflict-resolution.md.
Only modify the requested branch:
Force push safely:
--force-with-lease (never bare --force)--force-with-lease fails if the remote has unexpected commits, preventing data loss--force-with-lease fails, fetch and inspect before retryingConfirm before force pushing shared branches:
git log --format='%an' origin/<branch> | sort -u), warn the user that rebase will rewrite their collaborators' historygit pull --rebase or reset their local branch after the force pushPreserve all commits:
git log --oneline origin/$BASE_BRANCH..<feature-branch> before and afterWhen NOT to rebase:
update-branch skill instead)When reporting completion, be explicit about what happened:
Do say: "Rebased feature branch onto main — force pushed with lease to update remote"
Don't say: "Branch updated" (ambiguous — could be merge or rebase)
| Error | Resolution |
|---|---|
| No PR found for branch | Ask user for base branch, or create PR first |
| Dirty working tree | Ask user to stash or commit first |
| Rebase conflicts | Resolve per-commit, then git rebase --continue |
--force-with-lease rejected | Fetch, inspect new remote commits, ask user how to proceed |
| Rebase produces empty commits | Use git rebase --skip for truly empty commits |
| Authentication failure | Ensure gh and git are authenticated |
This skill works identically in CI and local environments:
git directly for all operationsuser.name and user.email appropriately