Changing your name in git

So you’re trans, a programmer, you’ve come out, you’ve changed your name.

Now what to do about that git history?

Step 1: Use your new name on all future commits

$ git config --global "Newfirstname Oldsurname"
$ git config --global ""

If you have ever set your name in the local repository you may need to remove it there also:

$ git config --unset
$ git config --unset

Step 2: Override your name on all local git history

$ echo "Newfirstname Newsurname <> \
        Oldfirstname Oldsurname <>" >> ~/.gitmailmap
$ git config --global mailmap.file ~/.gitmailmap
$ git config --global log.mailmap true

Step 3: Override your name for everyone else

This will mean your deadname and new name are connected in the repository. Skip this step if you’re not comfortable with this

$ echo "Newfirstname Newsurname <> \
        Oldfirstname Oldsurname <>" >> .mailmap
$ git add .mailmap
$ git commit -m "Add git .mailmap to correct Newfirstname"
$ git push

And have everyone run:

$ git config log.mailmap true

Step 4: Correct your name on all commits

This will mean rewriting the entire project history, and on large projects it may take hours. Skip this step if getting everyone to rebase their branches is too onerous

$ echo "Newfirstname Newsurname <> \
        Oldfirstname Oldsurname <>" >> .mailmap
$ curl | bash
$ git push origin --force --all
$ git push origin --force --tags

p.s. don’t run scripts from the internet