Interactive Rebase - Tidy Your History

git rebase -i

Interactive rebase rewrites your recent (local) commits - squash, reorder, reword, or drop them before sharing.

$ git rebase -i HEAD~4        # edit the last 4 commits

You get an editor listing the commits with a verb per line:

VerbAction
pickKeep the commit as-is
rewordKeep changes, edit the message
squashMerge into the previous commit (combine messages)
fixupLike squash but discard this message
dropDelete the commit entirely
(reorder lines)Reorder the commits
Tip: The classic use: turn "add feature / fix typo / oops / actually works" into one clean commit with squash/fixup before opening a PR. git commit --fixup=<hash> + git rebase -i --autosquash automates the ordering.
Danger: Interactive rebase rewrites commit IDs. Only do it on local, unpushed commits (or a branch only you use). Never rewrite shared history others have based work on.