Cleaning Up Commits
Interactive rebase.
Before you open a pull request, your branch might have messy commits. Fix typo. Work in progress. Oops. Interactive rebase lets you tidy them up, combining, renaming, or deleting commits, before anyone sees them.

- fix typo, wip, oops
- Tidy up before sharing
- Interactive rebase
Four messy commits
Here are our last four commits. Add gallery page, add photo, fix typo, and wip. They're really all one change. Let's squash them into a single commit. We type git rebase, dash i, head tilde four, which means let me edit the last four commits.
git log --oneline -n 4 d515d31 (HEAD -> main) wip b05c923 fix typo e15b311 Add photo b959963 Add gallery page git rebase -i HEAD~4 [detached HEAD ce1da56] Add gallery page Date: Mon Jan 5 09:29:41 2026 +0000 1 file changed, 4 insertions(+) create mode 100644 gallery.html Successfully rebased and updated refs/heads/main.
The todo list
Git opens your editor with a to do list. One line per commit, oldest first. Each line starts with a command, pick, which means keep it. We change the last three to squash, which means melt this commit into the one above. Then we save and close. Git combines all four, and opens the editor once more, so we can write the final message.
pick b959963 Add gallery page
squash e15b311 Add photo
squash b05c923 fix typo
squash d515d31 wipOne clean commit
Here's the result. The log now shows a single commit, add gallery page, containing all the changes.
git log --oneline -n 2 ce1da56 (HEAD -> main) Add gallery page f63a17a Link to about page git show --stat --oneline HEAD ce1da56 (HEAD -> main) Add gallery page gallery.html | 4 ++++ 1 file changed, 4 insertions(+)
Summary
Git rebase dash i opens a to do list of commits. Change pick to squash, to combine them. Only do this before you share them. Next, more things you can do in that list.
Key takeaways- git rebase -i HEAD~4
- pick = keep
- squash = combine