How does git merge –squash work?

Question:

I noticed that sometimes instead of git pull --rebase I do this

git checkout remote_my/branch_my
git merge --squash branch_my
git commit ...

What is the meaning of such a code

Answer:

From Git Reference – merge :

–squash

Treats the work area and index as if it were a merge, but does not actually commit, move the HEAD pointer, or write anything to $GIT_DIR/MERGE_HEAD . This allows you to make a single commit to the current branch, containing all the same changes that would have been applied in a normal branch merge (or multiple, in the case of a complex merge).

How it works

git checkout master
git merge --squash feature123
git commit -m'merged feature #123'

All changes in the feature123 branch become one commit in the master branch.

This is useful if the branch contains many minor commits that are "uninteresting" for the overall history. After such an operation, the branch history will remain "flat", just like after git pull --rebase .

Scroll to Top