Skip to content

Instantly share code, notes, and snippets.

@pallabpain
Last active September 13, 2022 06:40
Show Gist options
  • Save pallabpain/6f3b57e319a714dd2a5d5773128aaf18 to your computer and use it in GitHub Desktop.
Save pallabpain/6f3b57e319a714dd2a5d5773128aaf18 to your computer and use it in GitHub Desktop.
Squash commits when you have merge commits in between

Squash commits when you have merge commits in between

Let's assume that the feature branch is called feature and the main branch main:

  1. Create a temporary (say temp) branch from main:
git checkout -b temp main
  1. Squash the feature branch in:
git merge --squash feature
  1. Commit the changes (the commit message contains all squashed commit messages)
git commit
  1. Go back to the feature branch and point it to the temp branch:
git checkout feature
git reset --hard temp
  1. Delete the temporary branch:
git branch -d temp
  1. Push your changes to the remote branch
git push origin feature --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment