This script automatically re signs all commits on the current branch using your configured GPG key. It is useful when a pull request contains unverified commits and you want to replace them with verified, GPG signed commits.
The script:
- Detects the merge base with the target branch (default:
main). - Creates a backup branch before rewriting anything.
- Re signs every commit after that merge base.
- Force pushes the rewritten history to update the pull request.
You only need to have your PR branch checked out and your GPG signing configured.
- GPG is installed and working.
- Your GPG key is added to your GitHub account.
- The email in your git config is a verified email on GitHub.
- Your repository is clean (no uncommitted changes).
Check your settings:
git config user.email
git config user.signingkey
git config commit.gpgsignSave the script as:
resign-pr-commits.sh
Then make it executable:
chmod +x resign-pr-commits.shRun it from inside your repository while checked out on the PR branch:
./resign-pr-commits.sh./resign-pr-commits.sh [base-branch] [remote]
base-branchdefaults tomainremotedefaults toorigin
Examples:
./resign-pr-commits.sh
./resign-pr-commits.sh develop
./resign-pr-commits.sh main upstream- Ensures you are inside a git repository with a clean working tree.
- Detects the current branch.
- Fetches the latest base branch (default:
main). - Finds the merge base commit.
- Creates a backup branch such as:
backup/<your-branch>-before-resign-20250101T123456
- Runs:
git rebase --rebase-merges --exec 'git commit --amend --no-edit -S' <merge-base>This replays each commit and re signs it.
- Force pushes the updated branch:
git push --force-with-leaseAfter the push, your PR will show fully verified commits.
Only commits on your PR branch are rewritten. The script cannot modify commits that are already part of the base branch (main, develop, etc.).
If you still see unverified commits:
They cannot be rewritten. They will appear in the commit history view but they are not part of your PR changes.
This happens if:
- The email in the commit is not a verified email on GitHub.
- The GPG key used is not uploaded to GitHub.
Check the signature locally:
git show --show-signature -1If it shows Good signature, then you only need to fix email or GPG settings on GitHub.
If anything goes wrong, restore your backup branch:
git checkout backup/<branch-name>or reset your branch to that backup:
git checkout <original-branch>
git reset --hard backup/<branch-name>Yes. A backup branch is created every time, so your original commits are always recoverable.