CC-301e · Module 3
Rebase Strategies
3 min read
Rebasing with Claude Code requires careful prompt engineering because the operation is destructive — it rewrites history. The safe pattern is: tell Claude to rebase your feature branch onto the latest main, resolve any conflicts that arise, and verify the result compiles and passes tests. The unsafe pattern is: tell Claude to "clean up the git history" without specifying exactly what that means.
The key constraint is that Claude cannot use interactive rebase (git rebase -i). This means squashing, reordering, and editing commits during rebase must be done through non-interactive alternatives: git rebase --onto for moving branches, git merge --squash for collapsing a branch into a single commit, and git reset --soft HEAD~N followed by a new commit for squashing the last N commits.
# Squash last 3 commits into one (non-interactive)
git reset --soft HEAD~3
git commit -m "feat: combined feature implementation"
# Squash entire branch into one commit on main
git checkout main
git merge --squash feature/my-branch
git commit -m "feat: complete feature implementation"