This guide shows how to squash multiple commits into a single signed commit. It's useful when you've made several WIP commits and want to clean up your branch history before pushing or creating a pull request.
- A feature branch created from
main
(e.g.,feature/add-auth
) - At least two commits to be squashed
- Git commit signing (GPG/SSH/S/MIME) is already configured
git checkout feature/add-auth
git rebase -i HEAD~2
The editor will open showing something like:
pick abc123 WIP
pick def456 WIP 2
Change it to:
pick abc123 WIP
squash def456 WIP 2
Save and close the editor.
Git will open another editor with both commit messages. Edit and keep only what you want, for example:
feat: implement feature/add-auth feature
Save and close the editor again.
git commit --amend -S
This will reopen the editor with the commit message. Just save and close it to apply the signature.
git push --force
The branch feature/add-auth
will have a single, signed commit with your final message.