Open source contribution

Stage 2 · Lesson 7 of 7

Squashing and force-pushing safely

Git and GitHub for contributors

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

  • BookFree
    Pro Git

    Scott Chacon and Ben Straub

    Chapters 3, 5 and 6: branching, contributing to a project, and GitHub forks

Practise

  • The remote levels drill fetch, rebase and pushing while you watch the commit graph

Keep handy

Also worth your time

Mark this stage as not done?