Squash Merge: A Clean Story
Nine genuinely messy commits. One clean, real story on master — and the branch's own history, deliberately left behind.
feature/index-cards genuinely happened the way real work often does: nine commits, most of them vague, some of them outright unhelpful ("asdf", "try again"). The real content is fine — the commit history around it is not something master should inherit as-is.\n\ngit merge --squash takes the ENTIRE real diff the branch produced and stages it as one clean unit, letting you write one real, meaningful commit message for the whole thing. The real cost: the branch's own nine commits genuinely never become part of master's history — only their combined final result does.
Nine Genuinely Messy Real Commits
git log --oneline feature/index-cards -9
"WIP", "wip more", "asdf", "fix typo", "try again" — real, honest commit messages nobody would want in master's own permanent history.
Squashing the Entire Real Diff
git merge --squash feature/index-cards
git status
The entire real combined diff from all nine commits is staged as one unit — "Squash commit -- not updating HEAD" confirms no merge commit or branch history is being carried over yet.
One Real, Clean Commit
git commit -m "Add recipe index card storage guide"
One meaningful message, describing the real, finished result — none of the nine messy intermediate steps clutter master's history.
The Real Cost, Confirmed Directly
git branch -d feature/index-cards
warning: deleting branch 'feature/index-cards' that has been merged to
'refs/remotes/origin/feature/index-cards', but not yet merged to HEAD
A genuinely real warning: from git's own perspective, this branch's nine commits were never actually merged into master — only their squashed result was. The branch's own real history is gone the moment it's deleted.
git merge --squash
Stages the entire combined diff of a branch as one unit, without creating a merge commit or carrying over the branch's own commit history. Confirmed directly in this lab: "Squash commit -- not updating HEAD" appeared, and a single, real git commit afterward created exactly one new commit on master.
The real squash trade-off
Master gets one clean, meaningful commit instead of nine messy ones — genuinely better for anyone reading history later. The real cost: the branch's own nine commits are never part of master's ancestry, confirmed directly by git's own warning when later trying to delete the branch with plain -d.
📝 Create the Real, Messy History
Build a genuinely real branch the way messy exploratory work actually looks — nine vague commits.
cd ~/team-recipes && git switch -c feature/index-cardscd ~/team-recipes && printf 'Recipe Index Cards\n' > index-cards.md && git add index-cards.md && git commit -m 'WIP'cd ~/team-recipes && printf 'work in progress\n' >> index-cards.md && git add index-cards.md && git commit -m 'wip more'cd ~/team-recipes && printf 'a section\n' >> index-cards.md && git add index-cards.md && git commit -m 'asdf'cd ~/team-recipes && printf 'oops\n' >> index-cards.md && git add index-cards.md && git commit -m 'fix typo'cd ~/team-recipes && printf 'try again\n' >> index-cards.md && git add index-cards.md && git commit -m 'try again'cd ~/team-recipes && printf 'more\n' >> index-cards.md && git add index-cards.md && git commit -m 'more work'cd ~/team-recipes && printf 'almost\n' >> index-cards.md && git add index-cards.md && git commit -m 'almost done'cd ~/team-recipes && printf 'done?\n' >> index-cards.md && git add index-cards.md && git commit -m 'think this works'cd ~/team-recipes && printf 'Store recipe cards in a labeled box, organized by course.\n' >> index-cards.md && git add index-cards.md && git commit -m 'actually done now'cd ~/team-recipes && git push -u origin feature/index-cardscd ~/team-recipes && git log --oneline feature/index-cards -9student@lab:~$ cd ~/team-recipes && git switch -c feature/index-cards Switched to a new branch 'feature/index-cards' student@lab:~$ cd ~/team-recipes && printf 'Recipe Index Cards\n' > index-cards.md && git add index-cards.md && git commit -m 'WIP' [feature/index-cards ba76d5c] WIP 1 file changed, 1 insertion(+) create mode 100644 index-cards.md student@lab:~$ cd ~/team-recipes && printf 'work in progress\n' >> index-cards.md && git add index-cards.md && git commit -m 'wip more' [feature/index-cards 741e625] wip more 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'a section\n' >> index-cards.md && git add index-cards.md && git commit -m 'asdf' [feature/index-cards 3fc8d28] asdf 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'oops\n' >> index-cards.md && git add index-cards.md && git commit -m 'fix typo' [feature/index-cards 44f5441] fix typo 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'try again\n' >> index-cards.md && git add index-cards.md && git commit -m 'try again' [feature/index-cards 3c77d62] try again 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'more\n' >> index-cards.md && git add index-cards.md && git commit -m 'more work' [feature/index-cards 5b74044] more work 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'almost\n' >> index-cards.md && git add index-cards.md && git commit -m 'almost done' [feature/index-cards b17c3b3] almost done 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'done?\n' >> index-cards.md && git add index-cards.md && git commit -m 'think this works' [feature/index-cards 157f3c4] think this works 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && printf 'Store recipe cards in a labeled box, organized by course.\n' >> index-cards.md && git add index-cards.md && git commit -m 'actually done now' [feature/index-cards 0d449a0] actually done now 1 file changed, 1 insertion(+) student@lab:~$ cd ~/team-recipes && git push -u origin feature/index-cards Enumerating objects: 13, done. Counting objects: 100% (13/13), done. Compressing objects: 100% (10/10), done. Writing objects: 100% (13/13), 1.09 KiB | 1.09 MiB/s, done. Total 13 (delta 6), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git * [new branch] feature/index-cards -> feature/index-cards branch 'feature/index-cards' set up to track 'origin/feature/index-cards'. student@lab:~$ cd ~/team-recipes && git log --oneline feature/index-cards -9 0d449a0 (HEAD -> feature/index-cards, origin/feature/index-cards) actually done now 157f3c4 think this works b17c3b3 almost done 5b74044 more work 3c77d62 try again 44f5441 fix typo 3fc8d28 asdf 741e625 wip more ba76d5c WIP
📦 Squash the Entire Real Diff
Stage all nine commits' combined changes as one unit, ready for a single, clean commit.
cd ~/team-recipes && git switch mastercd ~/team-recipes && git merge --squash feature/index-cardscd ~/team-recipes && git statusstudent@lab:~$ cd ~/team-recipes && git switch master Switched to branch 'master' Your branch is up to date with 'origin/master'. student@lab:~$ cd ~/team-recipes && git merge --squash feature/index-cards Updating 67f9971..0d449a0 Fast-forward Squash commit -- not updating HEAD index-cards.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 index-cards.md student@lab:~$ cd ~/team-recipes && git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: index-cards.md
✅ Write the One Real, Clean Commit
Commit the squashed result with a single, meaningful message describing the real finished feature.
cd ~/team-recipes && git commit -m 'Add recipe index card storage guide'cd ~/team-recipes && git pushcd ~/team-recipes && git log --oneline -3student@lab:~$ cd ~/team-recipes && git commit -m 'Add recipe index card storage guide' [master ee10ef1] Add recipe index card storage guide 1 file changed, 9 insertions(+) create mode 100644 index-cards.md student@lab:~$ cd ~/team-recipes && git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 402 bytes | 80.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 To ../recipes-origin.git 67f9971..ee10ef1 master -> master student@lab:~$ cd ~/team-recipes && git log --oneline -3 ee10ef1 (HEAD -> master, origin/master, origin/HEAD) Add recipe index card storage guide 67f9971 Merge pull request: spice rack guide eb43506 Add freezer labeling recipe note
⚠️ See the Real Cost, Confirmed Directly
Try to delete the now-redundant branch, and read git's own honest warning about what squash actually did.
cd ~/team-recipes && git branch -d feature/index-cardsstudent@lab:~$ cd ~/team-recipes && git branch -d feature/index-cards warning: deleting branch 'feature/index-cards' that has been merged to 'refs/remotes/origin/feature/index-cards', but not yet merged to HEAD Deleted branch feature/index-cards (was 0d449a0).
Lab 2.3.3 complete. Nine genuinely messy commits, squashed into one clean, real story:\n\n\n Nine messy commits created : ✅ realistic exploratory work\n Entire diff squashed : ✅ staged as one unit\n One clean commit written : ✅ real, meaningful message\n Real cost confirmed by git : ✅ honest warning shown\n
Enable JavaScript to run the live terminal and track your progress.