Git squash with interactive rebase

With interactive rebase you can squash multiple commits in to one commit and edit commit message

As an example if you want to squash these commits in to one commit using git squash with interactive rebase

Git squash with interactive rebase

Initially start interactive rebase including 3 latest commits with command

git rebase -i head~3

Then the default editor opens the latest 3 commits

Git squash with interactive rebase

Next edit rows you want to squash to start with “squash” and close editor

Git squash with interactive rebase

The commit messages of the squashed commits open in the editor

Git squash with interactive rebase

Then edit message and close editor

Git squash with interactive rebase

Commits are squashed in to a single commit

Git squash with interactive rebase

Finally push the branch to the remote with force

git push origin feature -f