Resetting your Git author and email information

Resetting your Git author and email information involves two different scenarios: setting it correctly for future commits, and fixing it on past commits.

Part 1: Setting Your Author Info for FUTURE Commits

This is the most common requirement. You want all new commits you make from now on to have the correct name and email.

You can set this in two ways:

A) Globally (For All Your Projects)

This sets the author details for every Git repository on your system that doesn’t have a project-specific setting. This is what you want to do 99% of the time on your personal machine.

  1. Open your terminal or command prompt.
  2. Set your name:
    git config --global user.name "Your New Name"
  3. Set your email:
    git config --global user.email "your.new.email@example.com"

B) For a Single Project Only

If you want to use a different name or email for a specific project (e.g., a work email for a work project), you can set it locally.

  1. Navigate into your project’s directory:
    cd /path/to/your/project
  2. Run the same commands but without --global:
    git config user.name "Your Work Name"
    git config user.email "your.work.email@company.com"

    This local setting will always override your global setting for this project only.

How to Check Your Settings

You can easily verify what settings are active:

# Check the global setting
git config --global user.name
git config --global user.email

# Go into a project and check the local setting (it will show the global one if no local one is set)
git config user.name
git config user.email

Part 2: Changing the Author on PAST Commits

This is more complex and requires rewriting your project’s history.

⚠️ MAJOR WARNING: Rewriting history is a destructive action. It will change the unique ID (hash) of every commit you alter. If you have already pushed these commits and are collaborating with others, you must coordinate with your team before you do this. Forcing a push with rewritten history can create major problems for your collaborators.

Method A: If You ONLY Need to Fix the VERY LAST Commit

This is the easiest case. If you just made a commit and realized it has the wrong author:

git commit --amend --author="Your New Name <your.new.email@example.com>" --no-edit

The --no-edit flag prevents the command from opening your text editor, as you only want to change the author, not the commit message.

Method B: If You Need to Fix SEVERAL Past Commits

This is the most powerful method for complex history changes. You will run a script that goes through every commit and changes the author details where they match the old, incorrect email.

  1. Open your terminal and navigate to your project’s directory.
  2. Carefully copy and paste the entire script block below.
  3. CHANGE the OLD_EMAIL, CORRECT_NAME, and CORRECT_EMAIL variables to match your situation.
  4. Press Enter to run it.
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your New Name"
CORRECT_EMAIL="your-new-email@example.com"

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

This command will go through every branch and tag, inspect the author and committer of each commit, and replace the old details with the correct ones you provided.

Part 3: Pushing the Corrected History

After you have rewritten the history on your local machine using one of the methods in Part 2, a normal git push will be rejected by the server because your history no longer matches the remote history.

You need to “force push” to overwrite the remote history with your corrected local history.

  1. Make sure you have told your collaborators (if any) what you are about to do.

  2. Push your changes using the --force-with-lease flag. This is slightly safer than --force because it checks to make sure no one else has pushed to the branch in the meantime.

    git push --force-with-lease

Your Git author and email situation should now be fully reset.