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 emails
section. Take note of the sentence that calls outWe will instead use
followed by an email. Thatusers.noreply.github.com
email 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
~/.gitconfig
For my particular case though, I only wanted to update credentials for GitHub and not my repos hosted internally. That's where
includeIf
comes 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
tmp
folder, add the scripts in this gist to it,cd
intotmp
and 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
git
recommendsgit-filter-repo
instead of it's ownfilter-branch
install 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
.mailmap
within thetmp
folder. It's format looks like this:NEW_NAME <NEW_EMAIL> OLD_NAME <OLD_EMAIL>
So an example of remapping multiple items would be:
Nox <[email protected]> John Doe <[email protected]> Nox <[email protected]> jdoe <[email protected]>
Note that
.mailmap
items 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: