skills/mine/git-rebase/SKILL.md
Intelligently handle git rebase operations and resolve merge conflicts while preserving features and maintaining code quality. Use when rebasing feature branches, resolving conflicts across commits, and ensuring clean linear history without losing changes. Don't use for merge-commit workflows, cherry-picking individual commits, or initial repository setup.
npx skillsauth add pedronauck/skills git-rebaseInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For most rebases with multiple commits, use the squash-first strategy to resolve conflicts only once:
# Step 1: Backup current state
bash scripts/pre-rebase-backup.sh
# Step 2: Squash commits (interactive rebase on current branch)
git rebase -i $(git merge-base HEAD origin/main)
# Step 3: Rebase onto target
git rebase origin/main
# Step 4: If conflicts, resolve them once (see workflow below)
# Then continue: git rebase --continue
# Step 5: Force push safely
git push origin $(git rev-parse --abbrev-ref HEAD) --force-with-lease
This approach resolves conflicts once instead of per-commit, saving time and mental overhead.
Copy this checklist and mark progress:
Rebase Workflow:
- [ ] Step 1: Create safety backup
- [ ] Step 2: Fetch latest from target branch
- [ ] Step 3: Analyze conflict scope
- [ ] Step 4: Choose resolution strategy
- [ ] Step 5: Apply conflict resolutions
- [ ] Step 6: Validate merged code
- [ ] Step 7: Run tests
- [ ] Step 8: Force push safely
ALWAYS do this first. If rebase goes wrong, you can recover:
# Use the bundled script
bash scripts/pre-rebase-backup.sh
# Or manually create timestamped backup branch
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
git branch backup-rebase-$TIMESTAMP
# Alternative: Create temporary ref to your current commit
git reflog # Note your current HEAD SHA for manual recovery
This costs nothing and saves hours of work if something goes wrong.
Ensure you have the most recent remote state:
# Fetch without modifying local branches
git fetch origin
# View the divergence
git log --oneline origin/main..HEAD # Your commits
git log --oneline HEAD..origin/main # New commits on main
Understand how many commits you're rebasing and how much main has changed.
Before starting the rebase, predict conflicts:
# See which files you changed
git diff --name-only origin/main...HEAD
# See which files main changed
git diff --name-only origin/main HEAD
# Likely conflict areas: files changed in both
Key insight: If you changed auth.ts and so did main, you WILL get conflicts in auth.ts.
Anticipating conflicts helps you understand how to resolve them.
For detailed strategy comparison and decision matrix, see references/strategies.md.
When to use: Multiple feature commits with many conflicts expected
Why: Reduces conflicts to one resolution phase instead of per-commit
# Interactive rebase on current branch first
git rebase -i $(git merge-base HEAD origin/main)
# In editor, change all "pick" to "squash" (or 's') except first commit
# Save and exit - commits are squashed into one
# Edit commit message to describe the entire feature
# Now rebase the squashed commit
git rebase origin/main
# Resolve conflicts once, then git rebase --continue
Tradeoffs: Lose individual commit history, but simpler conflict resolution
When to use: 1-2 commits, clean history, or complex per-commit logic
git rebase -i origin/main
# In editor, you can:
# - Reorder commits to isolate conflict-prone ones
# - Drop commits that are already in main (git detects this)
# - Combine related commits before rebasing
# Save and exit - rebase proceeds, stopping at conflicts
Tradeoffs: More control, but more conflict-resolution iterations
When to use: Simple cases, no critical decisions, or in automated pipelines
# Rebase all commits at once
git rebase origin/main
# If no conflicts, done
# If conflicts, you resolve each one
Warning: Not recommended for complex scenarios. Use Strategies A or B instead.
When git rebase pauses with conflicts, use the analysis script:
# Analyze conflicts
bash scripts/analyze-conflicts.sh
# See which files conflict
git status
# For each conflicted file:
# - RECOMMENDED: Use merge tool for visual clarity
git mergetool --no-prompt
# - ALTERNATIVE: Manual edit in your editor
# Search for conflict markers: <<<<<<, ======, >>>>>>
<<<<<<< HEAD
// Your current feature code
function authenticate(token) {
validateToken(token);
return true;
}
=======
// Main branch code (incoming)
function authenticate(token) {
if (!token) throw new Error("No token");
validateToken(token);
setSession(token);
return true;
}
>>>>>>> origin/main
Decision framework (before deleting markers):
Can you keep both? YES → Merge them intelligently
function authenticate(token) {
if (!token) throw new Error("No token"); // Keep main's validation
validateToken(token);
setSession(token); // Keep main's session setup
return true; // Keep feature's return
}
Conflicting logic? Understand WHY they differ, then decide
Lost features? NEVER let a feature silently disappear
For detailed resolution patterns, see references/resolution-patterns.md.
✅ DO:
// Merged from both versions: main's validation + feature's session setup❌ DON'T:
After resolving conflicts, validate the merged code:
# Use the validation script
bash scripts/validate-merge.sh
# Manual checks:
# 1. Check syntax
npm run lint # or eslint, pylint, etc.
# 2. Check types (if TypeScript)
npm run type-check # or tsc --noEmit
# 3. Spot-check key files
git diff HEAD origin/main -- <conflicted-file>
# If validation fails:
# 1. Fix the issue in the file
# 2. git add <file>
# 3. git rebase --continue
Important: Validation catches mistakes BEFORE you commit them.
This is your safety net:
# Run full test suite
npm test
# Or specific tests for changed areas
npm test -- --testPathPattern=auth # If auth.ts was changed
# If tests fail:
# 1. Understand what broke
# 2. Fix in the files
# 3. git add <files>
# 4. git rebase --continue
Rule: Never force-push code that fails tests.
Use --force-with-lease instead of --force. It protects against accidentally overwriting others' work:
# SAFE: Protects others' commits
git push origin $(git rev-parse --abbrev-ref HEAD) --force-with-lease
# UNSAFE: Can overwrite others' work
git push origin your-branch -f # Don't do this
# If force-with-lease fails:
# Someone else pushed to your branch
# Coordinate with them before forcing
Use: Squash-first strategy
git rebase -i $(git merge-base HEAD origin/main)
# Mark all but first commit as 's' (squash)
# Save - commits squash into one
git rebase origin/main
# Resolve conflicts once
git rebase --continue
# Only one conflict-resolution phase!
Why: Each commit might have conflicts. Squashing before rebasing means one pass.
Use: Target that commit with interactive rebase
git rebase -i origin/main
# In editor, move the problematic commit to the end
# Save - rebase proceeds, stopping at that commit
# When it stops, you know exactly which commit conflicts
git status # See what changed in this commit
# Resolve, then continue
git rebase --continue
Why: Isolating the commit helps you understand what it's trying to do.
Use: Git rerere (reuse recorded resolution)
# Enable rerere globally (one-time setup)
git config --global rerere.enabled true
# Now when you hit the same conflict in a second commit,
# Git automatically applies the first commit's resolution
git rebase origin/main
# Git remembers your first conflict resolution
# and replays it automatically for similar conflicts
Why: When rebasing and hitting the same file repeatedly, rerere saves manual work.
Emergency escape plan:
# Abort the rebase - return to original state
git rebase --abort
# Fall back to merge (safer for complex scenarios)
git merge origin/main
# Or try a different approach:
# - Squash your entire feature branch first
# - Cherry-pick main's critical changes selectively
Important: It's okay to abort and rethink. Better than a broken rebase.
This skill includes helper scripts in scripts/:
pre-rebase-backup.sh: Creates a safety backup before rebasinganalyze-conflicts.sh: Analyzes current conflicts and provides detailed informationvalidate-merge.sh: Validates that merge/rebase is clean and ready for testingRun scripts with bash scripts/<script-name>.sh.
For detailed information on specific topics:
bash scripts/pre-rebase-backup.shgit fetch origingit merge origin/main)Default to merge if uncertain. Merge is safer for collaborative work.
Use rebase when: Solo feature branch, clean history matters, no shared dependencies.
Rebasing is a tool for creating clean, linear commit history. Used well, it makes debugging and code review easier. Used poorly, it loses work.
The key principle: Understand every conflict before resolving it. Don't automate away the thinking.
With this Skill, you can rebase with confidence, understanding each decision and protecting your code throughout the process.
development
Deep review of branch diffs, working trees, or GitHub PRs at any size. Use when the user asks for CodeRabbit-grade review, an incremental re-review after new pushes, publication of findings to a PR, a cross-LLM peer-review verdict round, or conformance review against spec artifacts. Don't use for applying fixes, reviewing specs or PRDs as documents, or quick single-file feedback.
tools
Orchestrate Claude and Codex worker TUIs from a controller agent through herdr panes and the herdr socket CLI. Use when delegating bounded tasks to herdr worker panes, running user-activated plan-first delegations (Claude Code plan mode, Codex Plan mode), waiting on native agent status (idle, working, blocked, done), or verifying worker reports. Workers launch as interactive TUIs via herdr agent start — never through headless runners (compozy exec, claude -p, codex exec). Not for cmux workspaces (see cmux-orchestration) and not for end-user herdr control.
tools
TanStack Query, Router, and Form patterns for React. Use when writing useQuery/queryOptions, mutations, caching, file-based routes, search params, loaders, or TanStack Form validation. Don't use for TanStack Start, TanStack DB/collections, Zustand client state, or non-TanStack routing.
development
Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.