I was recently working on a script on a library computer and pushed my local changes at the end of my session. Unfortunately, it wasn’t until later that night that I realized I had made commits under another GitHub user’s name. This is not a huge problem, but it bothered me to have someone else’s name listed in the commit history, so I went about fixing it.
GitHub has a help page on fixing this type of issue (https://help.github.com/articles/changing-author-info/), but I did not know the mystery user’s email so I modified the script as follows:
#!/bin/sh git filter-branch --env-filter ' OLD_NAME="old_username" CORRECT_NAME="my_username" CORRECT_EMAIL="firstname.lastname@example.org" if [ "$GIT_COMMITTER_NAME" = "$OLD_NAME" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_NAME" = "$OLD_NAME" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags
This takes advantage of the
$GIT_COMMITTER_NAME variable to find the incorrect user name and replace it with my information.
This should be enough to fix the issue, but if you’re like me you may have tried a few other things before finding the correct solution use
git push -f origin HEAD^:master to clear the latest commit.
Thanks for reading! If this post helped you, let me know on twitter so I know to keep writing stuff like this up.