Claude-skill-registry git-rebase
Performs git rebases with intelligent conflict resolution through commit message analysis. This skill should be used when rebasing branches, updating feature branches with latest main/master, resolving rebase conflicts, cleaning up commit history with interactive rebase, or when the user mentions "rebase", "squash commits", "update my branch", or has merge/rebase conflicts to resolve.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/git-rebase" ~/.claude/skills/majiayu000-claude-skill-registry-git-rebase && rm -rf "$T"
skills/data/git-rebase/SKILL.mdGit Rebase Assistant
Performs safe, effective rebases with intelligent conflict detection and resolution. The key differentiator is understanding the intent of both sides through commit message analysis before resolving any conflicts.
Core Principle: Intent Before Resolution
Never resolve a conflict mechanically. Before touching any conflict:
- Understand what master/main changed and WHY
- Understand what the feature branch changed and WHY
- Only then decide how to combine the changes
Workflow Decision Tree
User request │ ├─► "rebase", "update branch", "get latest main" │ └─► Full Rebase Workflow (below) │ ├─► Conflict during rebase │ └─► Conflict Resolution Workflow (below) │ └─► "squash", "clean up commits", "interactive rebase" └─► Interactive Rebase Workflow (below)
Full Rebase Workflow
Step 1: Validate Prerequisites
git status # MUST be clean git fetch origin # Get latest git branch --show-current # Confirm correct branch
Stop if: uncommitted changes exist, wrong branch, or detached HEAD.
Step 2: Create Safety Backup
git branch backup/$(git branch --show-current)-$(date +%Y%m%d-%H%M%S)
Step 3: Gather Full Context (MANDATORY)
Run
scripts/rebase-context.sh or manually gather:
# What's NEW in main since we branched? git log --oneline HEAD..origin/main # What are OUR commits? git log --oneline origin/main..HEAD # Files likely to conflict git diff --name-only origin/main...HEAD # Preview specific file changes on BOTH sides git log -p origin/main..HEAD -- <file> # Our changes to file git log -p HEAD..origin/main -- <file> # Their changes to file
Read the commit messages. Understand:
- What problems were solved in main?
- What new patterns/APIs were introduced?
- What assumptions might have changed?
Step 4: Execute Rebase
git rebase origin/main # Standard git rebase -i origin/main # Interactive (for squashing/reordering)
Step 5: Handle Conflicts
See Conflict Resolution Workflow below.
Step 6: Verify and Push
# Run tests/build npm test # or go test ./... or appropriate test command # Verify log looks correct git log --oneline -10 # Safe force push git push --force-with-lease
Step 7: Clean Up
git branch -d backup/<branch-name>-*
Conflict Resolution Workflow
Before Resolving ANY Conflict
Read
for detailed guidance.references/conflict-analysis.md
For each conflicted file:
# 1. See the conflict git diff --name-only --diff-filter=U # List conflicted files # 2. Understand THEIR side (what main added) git log -p ORIG_HEAD..origin/main -- <conflicted-file> # 3. Understand OUR side (what we're replaying) git log -p origin/main..ORIG_HEAD -- <conflicted-file>
Resolution Strategies
| Situation | Action |
|---|---|
| Main refactored shared code | Adapt our changes to new structure |
| Main added new feature | Integrate with our changes |
| Main fixed bug we also fixed | Evaluate which fix is better |
| Main changed API signature | Update our code to use new API |
| Both added similar code | Combine, avoiding duplication |
The Ours/Theirs Trap
Read
- this is critical.references/ours-vs-theirs.md
During rebase, the meaning is REVERSED from merge:
= the base branch (main)--ours
= your commits being replayed--theirs
# Accept main's version (during rebase) git checkout --ours <file> # Accept our feature branch version (during rebase) git checkout --theirs <file>
After Each Resolution
git add <resolved-files> git rebase --continue # Run tests after EACH commit if possible git rebase -i --exec "npm test" origin/main
Interactive Rebase Workflow
For squashing, reordering, or editing commits:
git rebase -i origin/main # Rebase onto main git rebase -i HEAD~5 # Edit last 5 commits
Interactive Commands
| Command | Use When |
|---|---|
| Keep commit as-is |
| Change commit message only |
| Stop to amend commit |
| Combine with previous, edit combined message |
| Combine with previous, discard this message |
| Remove commit entirely |
Squashing Best Practice
When squashing multiple commits:
- Read ALL commit messages being combined
- Craft a new message that captures the full intent
- Don't just keep the first message if others add context
Recovery
# Abort current rebase git rebase --abort # Restore from backup git reset --hard backup/<branch-name>-* # Find lost commits via reflog git reflog git reset --hard HEAD@{n}
Advanced Techniques
Autosquash Workflow
# During development, create fixup commits git commit --fixup=<commit-hash> # Later, autosquash during rebase git rebase -i --autosquash origin/main
Run Tests After Each Commit
git rebase -i --exec "npm test" origin/main
Preserve Merge Commits
git rebase --rebase-merges origin/main
Enable Rerere (Reuse Recorded Resolution)
git config --global rerere.enabled true
Git remembers conflict resolutions and auto-applies them next time.
Resources
scripts/
- Gathers context from both sides before rebaserebase-context.sh
references/
- Deep dive on understanding conflict intentconflict-analysis.md
- Explains the confusing reversal during rebaseours-vs-theirs.md