Frequently asked questions around Git and Version Control.
How can I change the author name / email of a commit?
Before we jump into solutions, let's find out what exactly it is you want to accomplish:
a) Change the author information before making a commit
b) Change the author information after making a commit (i.e. for historical commits)
Let's look at both cases in detail.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
In case you are using the Tower Git client, you can create and manage multiple "Committer Identities" - one for work, one for side projects, one for Open Source... You can then choose which profile you want to use on a per-repository or even a per-commit basis!
Changing the Author Information Just for the Next Commit
Finally, with the --author flag, you can also overwrite the author information for just the next commit:
git commit --author="John Doe <email@example.com>"
Editing the Author of Past Commits
Editing Past Commits Rewrites History!
No matter how exactly we change the information of past commits, there's one thing to always keep in mind: if we do this, we are effectively rewriting commit history. This is nothing to take lightly: you will create new commit objects in this process, which can become a serious problem for your collaborators - because they might have already based new work on some of the original commits. Therefore, think twice before you rewrite your commit history!
There are three basic ways to edit your past commits:
Using --amend for the Very Last Commit
In case you want to change just the very last commit, Git offers a very easy way to do this:
git commit --amend --author="John Doe <firstname.lastname@example.org>"
This effectively replaces the last commit with your "edited" version, correcting the wrong author information.
Using Interactive Rebase
Interactive Rebase is the Swiss Army Knife of tools in Git: it allows you to do and change almost anything. However, being as powerful as it is, this also means you can very easily shoot yourself in the foot. Use it with care (and possibly read up on it)!
The first step is to identify the last "good" commit and provide its hash to the rebase command:
$ git rebase -i -p 0ad14fa5
Your editor will open, requesting you to mark all the commits you want to change with the "edit" keyword.
Git will now walk you through each commit, giving you the chance to mold it as you desire:
Stopped at 5772b4bf2... Add images to about page
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
Your job, now, is to correct the author information and then continue to the next concerned commit object until you've edited all the commits you just marked:
$ git commit --amend --author="John Doe <email@example.com>" --no-edit
$ git rebase --continue
Using git filter-branch
Another way is to use Git's "filter-branch" command. It allows you to batch-process a (potentially large) number of commits with a script.
You can run the below sample script in your repository (filling in real values for the old and new email and name):
$ git filter-branch --env-filter '
NEW_NAME="New Name Value"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
if [ "$GIT_AUTHOR_EMAIL" = "$WRONG_EMAIL" ]
' --tag-name-filter cat -- --branches --tags
The same warning applies to this method as to the others mentioned: you are rewriting history with this command, creating new commit objects along the way!
Preferably, you should only do this in repositories that haven't been published / shared, yet. In any other case you should use it with extreme care - and only if you're aware of the side effects!