Git · Change Author Information

Before running this script, you’ll need:

  • The old email address that appears in the author/committer fields that you want to change
  • The correct name and email address that you would like such commits to be attributed to


Create a fresh, bare clone of your repository
1
2
git clone --bare https://hostname/user/repo.git
cd repo.git
Copy and paste the script, replacing the following variables based on the information you gathered
  • OLD_EMAIL
  • CORRECT_NAME
  • CORRECT_EMAIL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="[email protected]"
CORRECT_NAME="Your 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 the new Git history for errors.
Push the corrected history to GitHub Enterprise:
1
git push --force --tags origin 'refs/heads/*'