| name | git-rebase |
| description | MANDATORY: Use instead of `git rebase` - provides automatic backup and conflict recovery |
Git Rebase Skill
Purpose: Safely rebase branches with automatic backup, conflict detection, and recovery guidance.
PROJECT.md Merge Policy Check
Check PROJECT.md for configured merge preferences before rebasing.
MERGE_POLICY=$(grep -A10 "### Merge Policy" .claude/cat/PROJECT.md 2>/dev/null)
if echo "$MERGE_POLICY" | grep -qi "MUST.*merge commit"; then
echo "⚠️ WARNING: PROJECT.md prefers merge commits over rebase"
echo "Rebasing may conflict with configured workflow."
echo ""
echo "PROJECT.md specifies merge commits should be used, which preserves"
echo "branch history. Rebasing rewrites history to be linear."
echo ""
echo "Proceed only if you understand the implications:"
echo " - Rebasing will create linear history (no merge commits)"
echo " - This overrides the PROJECT.md preference"
echo ""
echo "To honor PROJECT.md preference, use 'git merge --no-ff' instead."
fi
Safety Pattern: Backup-Verify-Cleanup
ALWAYS follow this pattern:
- Create timestamped backup branch
- Execute the rebase
- Handle conflicts if any
- Verify immediately - history is correct
- Cleanup backup only after verification passes
Quick Workflow
BACKUP="backup-before-rebase-$(date +%Y%m%d-%H%M%S)"
git branch "$BACKUP"
git status --porcelain
git rebase <target-branch>
git log --oneline -10
git diff "$BACKUP"
git branch -D "$BACKUP"
Handling Conflicts
CRITICAL: Persist through conflicts. Never switch to cherry-pick mid-rebase (M241).
Rebase conflicts are normal and expected when branches have diverged. The solution is to resolve
conflicts and continue, not to abandon rebase for cherry-picking.
git status
git add <resolved-files>
git rebase --continue
git rebase --abort
git reset --hard "$BACKUP"
"Skipped previously applied" Messages
When rebasing, git may report "skipped previously applied commit" for commits whose changes already
exist on the target branch (perhaps added via separate commits). This is normal - git detects
content duplication and skips redundant commits. Continue the rebase.
Why Rebase Over Cherry-Pick
| Approach | Pros | Cons |
|---|
| Rebase | Preserves linear history, single operation | Must resolve conflicts sequentially |
| Cherry-pick | Can select specific commits | Creates duplicate commits, complex history |
Rule: Always complete a rebase. Cherry-pick is only appropriate for extracting a single commit
to a different branch, not for integrating branch changes.
Common Operations
Rebase onto base branch
CAT_BASE_FILE="$(git rev-parse --git-dir)/cat-base"
if [[ ! -f "$CAT_BASE_FILE" ]]; then
echo "ERROR: cat-base file not found. Recreate worktree with /cat:work." >&2
exit 1
fi
BASE_BRANCH=$(cat "$CAT_BASE_FILE")
git rebase "$BASE_BRANCH"
Interactive rebase (reorder, edit, squash)
git rebase -i <base-commit>
Safe Rebase Patterns
git rebase main
git rebase --all
git checkout feature
git rebase main
Error Recovery
git rebase --abort
git reset --hard $BACKUP
git reflog
git reset --hard HEAD@{N}
Verification After Amend/Fixup Operations
CRITICAL: When using rebase to amend or fixup a historical commit, verify the target commit
actually contains the expected changes.
TARGET_COMMIT="<original-hash>"
NEW_COMMIT=$(git log --oneline --all | grep "<partial-message>" | head -1 | cut -d' ' -f1)
git show "$NEW_COMMIT" --stat
git show "$NEW_COMMIT" -- path/to/expected/file.md
Common failure mode (M244): Rebase reports "Successfully rebased" but the fixup commit was
dropped due to conflicts. Always verify the target commit's contents before proceeding.
Success Criteria