Gitflow
🥞Squash 5 Commits Into OneMedium+500 XP
Workshop
Scenario reference

Squash 5 Commits Into One: the situation, step by step

The situation

Your PR has 5 commits: 'wip', 'wip2', 'fix tests', 'lint', 'finally'. Reviewers want one clean commit.

Interactive rebase, mark 1 as pick and the next 4 as squash (or s/f).

Medium · 3 steps · +500 XP

What you will practice

This scenario walks through 3 steps, in order:

  1. 01Start an interactive rebase of the last 5 commits
  2. 02Verify the new history
  3. 03Force push the squashed branch
Reveal the step-by-step commands

Try the terminal first — you learn more by doing. When you want to check yourself, here is the command for each step.

  1. 1. Start an interactive rebase of the last 5 commits
    git rebase -i HEAD~5
  2. 2. Verify the new history
    git log --oneline
  3. 3. Force push the squashed branch
    git push --force-with-lease

Key takeaway

`pick` the first, `squash` (or `fixup`) the rest. Edit the final message.