How to squash commits in GIT
Feb 16, 2025
Sometimes our GIT Commits History could be really a big mess.
In this case, we should use the GIT SQUASH command to improve it.
There are several way to do it but the method that I prefer is this one:
- Run
git reset --soft HEAD~3
to reset last 3 commits (change value after HEAD~ to determinate how many commits do you need to reset) - Use
git commit -a -m “An awesome commit message”
and write a good comment about your code changes - Push your code using
git push --force-with-lease origin
to rewrite the history on remote branch - If you have merged any branch into your working branch you should remerge it after the squash