Skip to content

Instantly share code, notes, and snippets.

@G07cha
Last active October 23, 2015 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save G07cha/a6b7779f0e8a8c0d70a7 to your computer and use it in GitHub Desktop.
Save G07cha/a6b7779f0e8a8c0d70a7 to your computer and use it in GitHub Desktop.
Easy script that allows to migrate all commits to new email and username, just call it with your username and email as arguments and wait until everything is finished.
#!/bin/sh
NAME=${1}
OLDEMAIL=${2}
EMAIL=${3}
curl --silent -X GET https://api.github.com/users/${NAME}/repos > repos.json
REPOS=$(cat ./repos.json | grep "\"html_url\": \"https://github.com/${NAME}/" | cut -d'"' -f4)
# Modified example https://help.github.com/articles/changing-author-info/
for i in ${REPOS[@]}; do
echo "Overwriting $i"
git clone --bare "$i"
cd $(basename "$i")
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "$OLDEMAIL" ]
then
export GIT_COMMITTER_NAME="$NAME"
export GIT_COMMITTER_EMAIL="$EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLDEMAIL" ]
then
export GIT_AUTHOR_NAME="$NAME"
export GIT_AUTHOR_EMAIL="$EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
git push --force --tags origin 'refs/heads/*'
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment