Skip to content

Instantly share code, notes, and snippets.

@trey
Last active November 14, 2024 15:14
Show Gist options
  • Save trey/9588090 to your computer and use it in GitHub Desktop.
Save trey/9588090 to your computer and use it in GitHub Desktop.
Change the email address for a git commit.

Change the email address for a git commit.

$ git commit --amend --author="Author Name <[email protected]>"

or

$ git commit --amend --reset-author

If you need to change the author for a commit older than the most recent, do a git rebase -i. For example, if you wanted to change the penultimate commit, you'd run:

$ git rebase -i HEAD~2

Then choose e or edit next to the appopriate commit, then when it asks you to amend, run the same command as you would for the most recent commit:

$ git commit --amend --reset-author

Then, to finish, you'd run:

$ git rebase --continue

And you're done. Don't forget you'll have to --force push if you've already pushed those commits to your remote.

source

@treymack-wk
Copy link

git commit --amend --reset-author --no-edit is cool to skip the editor.

@Reda-ELOUAHABI
Copy link

Reda-ELOUAHABI commented Jul 3, 2024

I had the same problem for 3 years of consistent contributions to many projects, and I didn't care about it. But the day I cared about them, I contacted GitHub support and did my research. Here are the "ready to go" steps:

  1. Take a commit URL, add .diff or .patch to the end of it, and check if the email there is your correct email used on GitHub. In my case, it was missing an "@".

  2. Execute these commands in PowerShell if you are using Windows; otherwise, search for the equivalent for your OS.

$callback = @"
if commit.author_email == b'incorrectEmail@...':
    commit.author_email = b'correctEmail@...'
    commit.author_name = b'YOUR_GITHUB_USERNAME'
if commit.committer_email == b'incorrectEmail@...':
    commit.committer_email = b'correctEmail@...'
    commit.committer_name = b'YOUR_GITHUB_USERNAME'
"@
git filter-repo --commit-callback "$callback" --force
  1. Add your remote repository URL.
git remote add origin YOUR_REPO_URL.git
  1. Fetch all branches from the remote.
git fetch --all
  1. Get a list of all local branches.
$branches = git branch | ForEach-Object { $_.Trim('* ').Trim() }
  1. Iterate through each branch.
foreach ($branch in $branches) {
    # Checkout the branch
    git checkout $branch

    # Pull updates from the remote branch
    git pull origin $branch

    # Push the branch to the remote repository
    git push -u origin $branch
}
  1. Switch back to the original branch (optional).
git checkout main # or master, or whichever is your default branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment