bashintermediate
Interactive Rebase — Squash and Reorder
Use git rebase -i to squash, edit, reorder, or drop commits before pushing to clean up history.
bashPress ⌘/Ctrl + Shift + C to copy
# Rebase last 5 commits interactively
git rebase -i HEAD~5
# In the editor:
# pick abc1234 feat: add login ← keep as-is
# squash abc1235 fix: login typo ← squash into previous
# reword abc1236 feat: add logout ← edit commit message
# edit abc1237 feat: add profile ← stop to amend
# drop abc1238 wip: debug stuff ← remove entirely
# After saving, Git replays commits with your changes.
# If you chose 'edit', make changes then:
git add .
git rebase --continue
# Abort if things go wrong:
git rebase --abort
# Force push after rebase (safe version):
git push --force-with-lease origin feature/my-branchSponsored
GitHub Copilot
Use Cases
- Cleaning commit history before merging a PR
- Squashing WIP commits into logical units
- Reordering commits for a cleaner changelog
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
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
bashadvanced
Git Rebase Strategies Guide
Advanced rebase strategies for cleaning history including onto, autosquash, and conflict resolution.
Best for: Cleaning commit history before merging
#git#rebase
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