bashadvanced
Git Rebase Strategies Guide
Advanced rebase strategies for cleaning history including onto, autosquash, and conflict resolution.
bashPress ⌘/Ctrl + Shift + C to copy
# Basic rebase onto main
git checkout feature-branch
git rebase main
# Interactive rebase to clean last 5 commits
git rebase -i HEAD~5
# In editor:
# pick abc1234 Add feature A
# squash def5678 Fix typo in A ← combines with previous
# pick ghi9012 Add feature B
# reword jkl3456 Old message ← edit commit message
# drop mno7890 Debug logging ← remove commit entirely
# Rebase --onto: move branch to different base
# Move feature from old-base to new-base
git rebase --onto new-base old-base feature-branch
# Autosquash: auto-arrange fixup commits
git commit --fixup abc1234
# Later:
git rebase -i --autosquash main
# Rebase preserving merge commits
git rebase --rebase-merges main
# Abort a rebase in progress
git rebase --abort
# Continue after resolving conflicts
git add resolved-file.ts
git rebase --continue
# Skip a conflicting commit
git rebase --skip
# Use rerere to remember conflict resolutions
git config rerere.enabled true
# Git will auto-apply same resolution next time
# Pull with rebase instead of merge
git pull --rebase origin mainUse Cases
- Cleaning commit history before merging
- Moving branches to a new base
- Automated fixup commit squashing
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashintermediate
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Best for: Keeping feature branches linear with main
#git#rebase
bashintermediate
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.
Best for: Cleaning up messy commit history
#git#squash
bashadvanced
Git Interactive Rebase Guide
Interactive rebase to reorder, edit, drop, and squash commits for a clean Git history.
Best for: Crafting a clean commit history before merge
#git#rebase
bashintermediate
Interactive Rebase — Squash and Reorder
Use git rebase -i to squash, edit, reorder, or drop commits before pushing to clean up history.
Best for: Cleaning commit history before merging a PR
#git#rebase