Last active
March 24, 2021 14:28
-
-
Save DallasO/f00f6a7e362e60f7a677bc4fb08eac9e to your computer and use it in GitHub Desktop.
For when you realize your personal email is made public to GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## | |
# Best to run these commands separately | |
## | |
## | |
# DISCLAIMER | |
# This will change the commit refs, therefore, anyone else using your repo will have to clone a new copy | |
## | |
# Clone bare copy of repo you'd like to fix | |
git clone --bare https://github.com/user/repo.git repo-cleanup && cd repo-cleanup | |
# Update the emails and name in the first few lines | |
# and run the following script inside that repo | |
git filter-branch --env-filter ' | |
OLD_EMAIL="[email protected]" | |
CORRECT_NAME="Correct Name" | |
CORRECT_EMAIL="[email protected]" | |
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_COMMITTER_NAME="$CORRECT_NAME" | |
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" | |
fi | |
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] | |
then | |
export GIT_AUTHOR_NAME="$CORRECT_NAME" | |
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" | |
fi | |
' --tag-name-filter cat -- --branches --tags | |
# Review code for errors | |
# push fixed commits to remotes as backup | |
git push --force --tags origin 'refs/heads/*' | |
# Remove temp repo when done | |
cd .. && rm -rf repo-cleanup | |
# for actual repo | |
# either delete all and clone again | |
rm -rf my-real-repo && git clone github.com/my-real-repo.git | |
# | |
# OR | |
# | |
# move current branch to a new one | |
git branch -m master master-backup | |
# pull the fixed master | |
git fetch | |
# check for errors | |
git checkout origin/master # && run tests, etc | |
# delete old branch | |
git branch -d master-backup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment