Three-step process to squash git commits.
First step
Check current branch name.
$ git branch --show-current
SITE-5000
Display commits.
$ git log --oneline -6
6ce8233 (HEAD -> SITE-5000) Update on branch SITE-5000 #4 6a25fe3 Update on branch SITE-5000 #3 30885c7 Update on branch SITE-5000 #2 df9c454 Update on branch SITE-5000 #1 8ccf509 (origin/SITE-4999, SITE-4999) Update on branch SITE-4999 #1 605b30b (origin/main, main) first commit
Count commits on the current branch that is not tracked remotely.
$ git rev-list HEAD --not --remotes=*/* --count
4
Things are different when the current branch is already tracked remotely.
$ git log --oneline -6
6ce8233 (HEAD -> SITE-5000, origin/SITE-5000) Update on branch SITE-5000 #4 6a25fe3 Update on branch SITE-5000 #3 30885c7 Update on branch SITE-5000 #2 df9c454 Update on branch SITE-5000 #1 8ccf509 (origin/SITE-4999, SITE-4999) Update on branch SITE-4999 #1 605b30b (origin/main, main) first commit
Determine the parent branch.
$ git show-branch --topo-order
! [SITE-4999] Update on branch SITE-4999 #1 * [SITE-5000] Update on branch SITE-5000 #4 ! [main] first commit --- * [SITE-5000] Update on branch SITE-5000 #4 * [SITE-5000^] Update on branch SITE-5000 #3 * [SITE-5000~2] Update on branch SITE-5000 #2 * [SITE-5000~3] Update on branch SITE-5000 #1 +* [SITE-4999] Update on branch SITE-4999 #1 +*+ [main] first commit
Count commits on the current branch.
$ git rev-list HEAD --not --remotes=*/SITE-4999 --count
4
Second step
Reset the current HEAD to specific point in time you got earlier.
$ git reset --soft HEAD~4
Commit all changes as a single commit.
$ git commit -m "All-in-one update"
Alternatively, use an interactive mode.
$ git rebase --interactive HEAD~4
Third step
Push changes to the repository.
Additional notes
Simplest possible use case.
$ git reset --soft HEAD~$(git rev-list HEAD --not --remotes=*/main --count)
$ git commit -m "SITE-5555 Update blog post"
$ git push --force