Squashing is the process of taking multiple commits and combining them into a single commit encapsulating all the changes from the initial commits.
Pay special attention when squashing commits on a branch that is tracking a remote branch; if you squash a commit that has already been pushed to a remote branch, the two branches will be diverged, and you will have to use git push -f
to force those changes onto the remote branch. Be aware that this can cause issues for others tracking that remote branch, so caution should be used when force-pushing squashed commits onto public or shared repositories.
If the project is hosted on GitHub, you can enable "force push protection" on some branches, like master
, by adding it to Settings
- Branches
- Protected Branches
.