Rebase current branch onto base branch with smart conflict resolution.
Use Case
- •PR has conflicts with main/master
- •Need to update feature branch with latest changes
- •Clean up branch history before merge
Process
- •Safety check: Prevent running on protected branches (main, master, develop)
- •Detect base branch: Usually
mainormaster - •Fetch and rebase:
bash
git fetch origin <base> git rebase origin/<base>
- •Handle conflicts automatically
Conflict Resolution Strategy
Lockfile Conflicts (Auto-resolve)
Lockfile conflicts are resolved by reinstalling:
- •Accept incoming version:
git checkout --theirs <lockfile> - •Reinstall based on package manager:
- •
package-lock.json→npm install - •
yarn.lock→yarn install - •
pnpm-lock.yaml→pnpm install
- •
- •Stage and continue:
git add <lockfile> && git rebase --continue
Code Conflicts (Smart merge)
Auto-resolve cases:
- •Both sides add imports → keep all imports
- •Both sides add functions/variables → keep both
- •Duplicate lines → remove duplicates
Ask user cases:
- •Same line modified differently
- •Logic conflicts
- •Ambiguous merges
Resolution Flow
code
Conflict detected ├─ Lockfile only → auto reinstall → continue ├─ Code (simple) → Claude merges both sides → continue ├─ Code (complex) → show conflict, ask user └─ Mixed → resolve lockfile first, then code
Safety Features
- •Protected branches: Never rebase main/master/develop
- •force-with-lease: Safer than
--force - •Smart conflict detection: Categorize before attempting resolution
Execution Steps
- •Check current branch is not protected
- •Run
git fetch originto get latest - •Detect base branch (main or master)
- •Run
git rebase origin/<base> - •If conflicts:
- •Identify conflict type (lockfile vs code)
- •Apply appropriate resolution strategy
- •Continue rebase with
git rebase --continue - •Repeat until complete
- •Push with
git push --force-with-lease
Examples
Clean rebase:
code
/stylish-rebase → Current branch: feature/add-button → Fetching origin/main... → Rebasing onto origin/main... → No conflicts ✅ → Pushing with --force-with-lease... → Done ✅
Lockfile conflict:
code
/stylish-rebase → Rebasing onto origin/main... → Conflict: package-lock.json (lockfile) → Auto-resolving: npm install... → Continuing rebase... → Done ✅
Code conflict (auto-resolved):
code
/stylish-rebase → Conflict: src/utils.ts → Analyzing... both sides add different imports → Merging: keeping all imports → Continuing rebase... → Done ✅
Code conflict (needs input):
code
/stylish-rebase → Conflict: src/api.ts → Same function modified differently on both sides → Showing both versions... → Which version to keep? (ours/theirs/manual)
Protected branch error:
code
/stylish-rebase → Error: Cannot rebase on protected branch 'main' → Switch to a feature branch first