Git: “Squash” your commits – alternative solution

Sometimes you will have a pull request that is full of merge commits mixed with regular commits. These branches are a little tricky to squash. I’m here going to show a trick that I sometimes use.

Stand in your pull request branch and run:

git reset --soft origin/master

This resets us back to master but keeps all our changes in staged, ready for us to commit in to one new commit:

git commit -m"My one commit message for all changes"

After this we need to replace all the commits in our pull request with the new one we have in our local

git push -f

We should now have only one commit in our pull request

Tested on Git v2.24.3 and OSX 10.15.6

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.