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 user.name "Newfirstname Oldsurname"
$ git config --global user.email "newemail@example.com"

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

$ git config --unset user.name
$ git config --unset user.email

Step 2: Override your name on all local git history

$ echo "Newfirstname Newsurname <newemail@example.com> \
        Oldfirstname Oldsurname <oldemail@example.com>" >> ~/.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 <newemail@example.com> \
        Oldfirstname Oldsurname <oldemail@example.com>" >> .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 <newemail@example.com> \
        Oldfirstname Oldsurname <oldemail@example.com>" >> .mailmap
$ curl https://raw.githubusercontent.com/robotdana/dotfiles/master/scripts/rename.sh | bash
$ git push origin --force --all
$ git push origin --force --tags

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