Jeevachaithanyan Sivanandan

How to Change Git Commit Ownership (Author & Committer)

In Version Control, Tutorial · 3 min read

Understanding Git Identities: Author vs. Committer

  • Author: The person who originally wrote the code changes.
  • Committer: The person who applied the changes to the repository. This is often the same as the author, but can differ (e.g., if you apply a patch from someone else, you are the committer, but they are the author).

When you commit, Git uses the user.name and user.email configured in your local Git settings (or global settings) to populate both the author and committer fields.

Why You Might Need to Change Ownership

  • Typo or incorrect email: You simply made a mistake in your Git configuration.
  • Work vs. Personal Identity: You used your personal email for a work project (or vice-versa).
  • Pair Programming: You paired with someone and the commit ended up under the wrong person’s identity.
  • Migrating History: You’re importing commits from another system or account.

Scenario 1: Changing the Most Recent Commit (Already Pushed)

If only your very last commit has the wrong ownership and it’s already on the remote, this is the simplest fix.

  1. Ensure you’re on the correct branch:
  2. Amend the commit:
  3. Force Push: Since the commit’s hash has changed, you need to force push to update the remote.

Scenario 2: Changing Multiple or Older Commits (Already Pushed)

This is a more common scenario and requires an interactive rebase.

  1. Backup (Optional but Recommended): Before any major history rewriting, consider backing up your repository.
  2. Navigate to your local repository and the correct branch:
  3. Identify the commits: Run git log to find the commits you want to change. Note down the commit hash of the commit just before the first commit you want to modify.
  4. Start the Interactive Rebase: Replace AAAAAAA with the commit hash you identified in the previous step.
  5. Mark Commits for Editing: For each commit whose author/committer you want to change, replace pick with edit.
  6. Amend Each Commit: Git will now pause at the first commit you marked (XXXXXXX). You’ll see a message like:
  7. Verify and Force Push: After the rebase completes, use git log to confirm the author/committer details are correct. Then, force push to update your remote repository:

Scenario 3: Changing Authorship for Initial Commits or Many Commits Across History

If the commits you want to change are among the very first commits in the repository (i.e., they have no parent commit that is correct), or if you need to change a large number of commits throughout the entire history, git filter-branch (or the newer git-filter-repo) is the right tool. git filter-branch is built-in.

  1. Backup (Highly Recommended!): This is especially important with filter-branch as it can be more destructive.
  2. Navigate to your local repository and the correct branch:
  3. Run git filter-branch: This command rewrites history by checking each commit’s author/committer and changing it if it matches the OLD_EMAIL.
  4. Clean up filter-branch remnants: git filter-branch creates backup refs. You can clean them up after verifying the changes.
  5. Verify and Force Push: Check git log to ensure all affected commits now show the correct author. Then, force push all branches and tags to your remote:

Verifying on GitHub

After force-pushing, refresh your GitHub repository page. The commits you modified should now display the correct author/committer. For GitHub’s contributions graph to attribute these commits to your main profile, ensure that the your.correct.email@example.com you used is also a verified email address associated with your GitHub account settings.