Re-Sign Git Commits Without Editing Them

git

September 8, 2026  |  2 min read

Re-signing rewrites a commit, so the hash changes even when its files and message do not. Check the range first and use --force-with-lease for an already-pushed branch.

Re-Sign HEAD

git commit --amend --no-edit -S

--no-edit keeps the message. -S signs the replacement commit. Add --no-verify only when you deliberately want to skip commit hooks.

Re-Sign a Linear Branch

git fetch origin
git log --oneline origin/main..HEAD
git rebase --exec 'git commit --amend --no-edit --no-verify -S' origin/main
git log --show-signature origin/main..HEAD
git push --force-with-lease

The rebase command replays every commit after origin/main, then amends and signs each replayed commit. Use it for a linear branch. Review merge-heavy history separately before rewriting it.

Bonus: Reset the Author

git commit --amend --no-edit --reset-author -S

--reset-author replaces the author with the current user.name and user.email, and renews the author timestamp. Include it in the rebase command when every replayed commit needs the same correction.

Bonus: Sign With SSH

git config --global gpg.format ssh
git config --global user.signingKey ~/.ssh/id_ed25519.pub
git config --global commit.gpgSign true

The matching private key must be available through ssh-agent. Register the public key as a signing key in GitHub or GitLab to receive a verified badge:

gh ssh-key add ~/.ssh/id_ed25519.pub --type signing

Refs