Stage 2 · Lesson 7 of 7
Squashing and force-pushing safely
Many projects want a to land as one or a few clean commits, without noise like "fix typo" and "address review". means combining several commits into one. You can squash with an interactive rebase on your branch, or with git reset --soft upstream/main followed by one new commit.
This rewrites history, so you push the new branch with git push --force-with-lease. Force-pushing replaces the branch on the remote with your version. Plain --force does this blindly.
--force-with-lease refuses if the remote branch has commits you have not seen, such as a fix a pushed to your branch, so you do not destroy them. Only rewrite your own . Check the first.
Many projects squash on merge themselves, and some reviewers want new commits during review so they can see what changed.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with
- BookFreePro Git
Scott Chacon and Ben Straub
Chapters 3, 5 and 6: branching, contributing to a project, and GitHub forks