Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What does git merge --squash do?

SHORT ANSWER

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

bash
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 unmerged

What 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.

#git#merge#squash

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.