Skip to content

Instantly share code, notes, and snippets.

@bitjockey42
Created August 28, 2019 05:26
Show Gist options
  • Save bitjockey42/b171600f86181f183855292176ca1265 to your computer and use it in GitHub Desktop.
Save bitjockey42/b171600f86181f183855292176ca1265 to your computer and use it in GitHub Desktop.
Change git author for all commits in current repo; based on https://help.github.com/en/articles/changing-author-info
#!/usr/bin/env bash
export CURRENT_GIT_EMAIL=$(git config --get "user.email")
export CURRENT_GIT_USER=$(git config --get "user.name")
echo "CURRENT_USER: $CURRENT_USER"
echo "CURRENT_EMAIL: $CURRENT_EMAIL"
echo -n "Enter new user name and press [ENTER]: "
read NEW_NAME
echo -n "Enter new email and press [ENTER]: "
read NEW_EMAIL
export NEW_GIT_USER=$NEW_NAME
export NEW_GIT_EMAIL=$NEW_EMAIL
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "$CURRENT_GIT_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_GIT_USER"
export GIT_COMMITTER_EMAIL="$NEW_GIT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$CURRENT_GIT_EMAIL" ]
then
export GIT_AUTHOR_NAME="$NEW_GIT_USER"
export GIT_AUTHOR_EMAIL="$NEW_GIT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment