Sometimes you have pushed a whole bunch of commits and want to create a PR from your branch. The problem is your commits are messy and people will judge you for it when they are reviewing your PR.
How I do it now
Use interactive rebase.
git switch <branch-you-want-to-squash>Let’s say you want to squash this and merge into develop
git rebase -i developChange everything to fixup except the first
pick a1b2c3 Add login form
fixup d4e5f6 Fix styling
fixup 789abc Add forgot password linkIf you don’t do anything now and just commit you will get the commit message of the first commit you are keeping.
How I used to do it
git checkout my_branch
git reset --soft HEAD~{NUMBER_OF_COMMITS}
git commit
git push --force origin my_branchTo count the number of commits in your current branch compared to develop you can do this
git rev-list --count develop..HEAD