If you haven’t set up GPG signing, check out my previous post on this here.
Say you created a new branch from main
called my-branch
. This guide will help you to sign all of the commits that are in my-branch
that are not in main
.
For starters, do a git fetch origin
so that we are up to date with remotes. Be on my-branch
. Ensure that you are rebased correctly from the main
branch. This is not so important but will keep things clean and make it easy to merge later.
git rebase origin/main
Resolve conflicts, if any. Ensure clean state. Now to retroactively sign commits on my-branch
, run:
git rebase --exec 'git commit --amend --no-edit -n -S' -i origin/main
Being on my-branch
basically what you are saying here is that:
- Start an interactive rebase from the last known commit that is on
origin/main
, rolling back temporarily. - For every commit, execute (
--exec
) git commit command, amending each commit without modifying its contents and signing every commit
Hope this helps.
This helped me in a pinch. It’s worth noting that when you attempt to push you’re going to get an error stating something like “hint: Updates were rejected because the tip of your current branch is behind”…
A force pushed resolved this for me