What does git merge --squash do?
It combines all changes from a branch into the working tree and staging area as one set of changes, without creating a merge commit. You then commit once, so the branch's many commits become a single commit on main.
Explain it simply
Think of a notebook full of rough work. Before submitting, you copy only the final answer onto a clean sheet. The scribbles stay in the notebook but the teacher sees one tidy page.
git merge --squash feature applies the net result of the feature branch to your current branch and stops, with changes staged. You write one commit message. Git does not record feature as merged, so the branch still looks unmerged and you delete it with -D. The cost is that individual commits and their authorship are lost from main. GitHub's 'Squash and merge' button does the same thing.
Example
git switch main
git merge --squash feature/profile-page
git commit -m "Add profile page"
git branch -D feature/profile-page # -d refuses, Git sees it as unmergedWhat to say in the interview
"merge --squash takes the combined changes of a branch and stages them without a merge commit, so I make a single commit on main. It keeps main tidy but loses the detailed commit history, and Git does not treat the branch as merged, so deleting it needs -D."
Common mistakes
- Using git branch -d afterwards and being confused that Git says the branch is not fully merged.