This came about because I saw how easy it was to view my info (name and email) by just adding .patch at the end of a commit URL on GitHub.
-
Go to https://github.com/settings/emails to view your current mappings for emails. For each email there'll be a
Not visible in emailssection. Take note of the sentence that calls outWe will instead usefollowed by an email. Thatusers.noreply.github.comemail is the one that's going to be used going forward.- Also make sure these items are checked
[X] Keep my email addresses private [X] Block command line pushes that expose my email
- Also make sure these items are checked
-
First update your local credentials
git config --global user.name "<NEW_NAME>" git config --global user.email "<NEW_EMAIL>"
or just directly edit
~/.gitconfigFor my particular case though, I only wanted to update credentials for GitHub and not my repos hosted internally. That's where
includeIfcomes in (you have to have at least gitv2.36).Open
.gitconfig[user] email = <OLD_EMAIL> name = <OLD_NAME> + + [includeIf "hasconfig:remote.*.url:*github.com:*/**"] + path = ~/.gitconfig.github + + [includeIf "hasconfig:remote.*.url:*gist.github.com*"] + path = ~/.gitconfig.github
Create a new file
~/.gitconfig.github, and add[user] email = <NEW_EMAIL> name = <NEW_NAME>
To verify run:
git config --get user.email && git config --get user.name -
If you already have a GitHub token, you can skip this step. Go to https://github.com/settings/tokens?type=beta (to create a Fine Grained Token) and click
Generate Token.Token name: Change Repo Author Expiration: (chose Custom, and set it to last a day) Repository access: All repositories Permissions: Metadata [Read-Only] (click Generate token) (copy and store the token) -
Create a
tmpfolder, add the scripts in this gist to it,cdintotmpand runchmod +x *.sh. -
Run
GH_TOKEN="<YOUR_TOKEN>" ./scrape-urls.sh. When it's done scraping, it'll print the number of URLs it found, make sure that matches what's in your repo (public & private combined). -
Since
gitrecommendsgit-filter-repoinstead of it's ownfilter-branchinstall it withsudo apt install git-filter-repo. More install instructions can be found on https://github.com/newren/git-filter-repo/blob/main/INSTALL.md#simple-installation or https://andrewlock.net/rewriting-git-history-simply-with-git-filter-repo/#installing-git-filter-repo-using-docker. -
Create a
.mailmapwithin thetmpfolder. It's format looks like this:NEW_NAME <NEW_EMAIL> OLD_NAME <OLD_EMAIL>So an example of remapping multiple items would be:
Nox <the0neWhoKnocks@users.noreply.github.com> John Doe <zippy@hotmail.com> Nox <the0neWhoKnocks@users.noreply.github.com> jdoe <flimflam@gmail.com>Note that
.mailmapitems take precedence over what you put in your.gitconfig, but it needed to be updated so that future commits have the correct info. -
Run
./update-author.sh.- Few things to note:
- If you want to test things before pulling the trigger
- # git-filter-repo --dry-run --mailmap "../.mailmap" - git-filter-repo --quiet --mailmap "../.mailmap" + git-filter-repo --dry-run --mailmap "../.mailmap" + # git-filter-repo --quiet --mailmap "../.mailmap" ... - git push --force --all origin - git push --force --tags origin + # git push --force --all origin + # git push --force --tags origin
- If something goes wrong and you want to undo the changes, go into
repos.bak/<REPO_NAME>and rungit push --force --all origin git push --force --tags origin
- If you want to test things before pulling the trigger
- Few things to note:
- If you have something like a
CHANGELOG.mdin your repo that references past commit SHAs, you'll have to manually edit those references. Otherwise they'll point to nonexistent references. - You may already have a repo checked out elsewhere. If you try to create/push new tags, you'll likely get an error mentioning
would clobber existing tag. You'll have to pull in the updated tags to get past this.git fetch --tags --force