Skip to content

Instantly share code, notes, and snippets.

@poqdavid
Last active July 29, 2025 03:57
Show Gist options
  • Select an option

  • Save poqdavid/2509214dd9132f6ec77685673baea4de to your computer and use it in GitHub Desktop.

Select an option

Save poqdavid/2509214dd9132f6ec77685673baea4de to your computer and use it in GitHub Desktop.
How to rename author and resign all commits

1. Rename author

Note that filter-repo deletes remote section in .git\config

git filter-repo --mailmap mymailmap --force

or

git-filter-repo --name-callback 'return name.replace(b"<OLD NAME>", b"<NEW NAME>")'

2. Sign all commits

git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all

or

This option is for signing all commits for specific author name

git filter-branch -f --commit-filter '
if [ "$GIT_AUTHOR_NAME" = "<AUTHOR>" ];
then
    git commit-tree -S "$@";
fi' -- --all

3. Delete all backups/dupes made by filter-branch

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now

4. Force push to origin

git push --force --tags origin 'refs/heads/*'
@ishepherd
Copy link
Copy Markdown

ishepherd commented Jul 29, 2025

2. Sign all commits

For some reason, Github rejected my push as (it claimed) the first commit signature could not be verified?

  • Would the step 2 command touch first commit?
  • (Maybe all commits were a problem and Github just complained about the first?)

As my repo has only ever had default main branch, I replaced this step with a git rebase

git rebase -i --root --exec 'git commit --amend --no-edit -n'

which worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment