Data report"State of code review 2024" is now liveRead the full report

How to change the author of a Git commit

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


In Git, each commit is associated with an author and a committer. Sometimes, it may be necessary to change the author details of a commit—perhaps due to a misconfiguration of user details or when migrating commit histories between projects. This guide will walk you through the process of changing the author of a Git commit, covering various scenarios from a single commit amendment to changing the authorship of multiple commits across a project’s history.

Before diving into the procedures, it’s important to distinguish between an "author" and a "committer":

  • Author: The person who originally wrote the code.
  • Committer: The person who last applied the code to the repository, which could be different in cases of patches or collaborative projects.
Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more

If you've realized that your commit authorship details are incorrect across many projects, you might want to update your global Git configuration:

Terminal
git config --global user.name "New Author Name"
git config --global user.email "new.author@example.com"

This example changes the author config at the "global" level, but Git offers several levels of configuration settings, each catering to different scopes: system, global, and local.

The system level affects all users on a machine and all their repositories; settings are typically stored in a configuration file accessible system-wide, such as /etc/gitconfig.

The global level applies to every repository the current user works with on the machine, with settings usually found in the user’s home directory, for example, ~/.gitconfig or ~/.config/git/config.

The local level is specific to a particular repository and overrides system and global settings; these configurations are stored in .git/config within the repository itself.

The author can be set separately at each level with order of precedence: local, global, then system.

To change the author information for the most recent commit run:

Terminal
git commit --amend --author="New Author Name <new.author@example.com>"

This command opens your default text editor to edit the commit message, and it replaces the author details with the new ones specified.

While Git is an incredibly useful tool, it has many shortcomings, particularly with rebasing, and managing stacked pull requests.

The Graphite CLI simplifies git, handles rebasing automatically, and allows you to create, submit, and stack pull requests right from the command line.

Under the hood, the CLI runs Git to create branches, commits, and metadata, which means you can still use Git in your scripts, tooling, or whenever you feel like it. Read more about installing the Graphite CLI in our docs.

screenshot of the Graphite CLI

If the commit has already been pushed to a remote repository (like GitHub) and needs to be corrected, perform the amendment locally as shown above, and then force-push the changes:

Terminal
git push --force

Note: Force-pushing can disrupt the history for other collaborators. It should be used with caution, particularly in shared repositories.

To change the author of a specific commit that isn't the most recent, you'll need to use an interactive rebase:

  1. Start an interactive rebase up to the commit you want to change:

    Terminal
    git rebase -i <commit-id>^

    Replace <commit-id> with the hash of the commit just before the one you want to amend.

  2. In the text editor that opens, change the word pick to edit next to the commit you want to amend, then save and close the editor.

  3. Amend the commit:

    Terminal
    git commit --amend --author="New Author Name <new.author@example.com>"
  4. Continue the rebase:

    Terminal
    git rebase --continue
The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free

For further reading on commit authors see the official Git documentation.

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2