Clean git history with fixup and autosquash
April 6, 2025
When you spot something to fix in an earlier commit, don’t just commit with “fix typo”. Use --fixup to tie it to the original commit:
# Find the commit to fix
git log --oneline
# Create a fixup commit targeting that SHA
git commit --fixup <sha>
# Before pushing, squash them together
git rebase -i --autosquash main
Git will automatically reorder and mark the fixup commit for squashing. Your history stays clean, and reviewers see coherent commits instead of a trail of corrections.
You can also set autosquash as the default:
git config --global rebase.autosquash true