1 min read

Clean up git history with interactive rebase


Tidy commits before pushing

Squash the last 5 commits interactively:

rebase.sh
git rebase -i HEAD~5

In the editor, change pick to squash (or s) for commits you want to fold into the previous one:

rebase_editor
pick abc1234 Add feature
squash def5678 Fix typo
squash ghi9012 More fixes
pick jkl3456 Add tests

Rebase onto main before merging your feature branch:

rebase_main.sh
git fetch origin
git rebase origin/main

If something goes wrong:

rebase_abort.sh
git rebase --abort