How to Change Git Commit Author and Email for the Last Commit?

You can change the author name and email for the last git commit by using the following command:

git commit --amend --author="Your Name <[email protected]>" --no-edit

Please note that the email must be entered within the angled brackets (<...>).

Running the command above will change the author name for the last commit locally. To reflect the changes in your remote repository, you must run the following command after:

git push --force-with-lease

You can monitor the changes by running the git log command before/after each command.

If the email you specify does not match the one associated with your git account, then it might show two different people as "authored" and "committed". In this case, you can either add the email in your git account (for example, you can do so in "Emails" settings in GitHub), or you can amend the git commit again with the right email address. If you choose to add the email in your git account (or if it already exists), then depending on the git service you use, it might show your username instead of the author name you specified.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.