24

How do I change the author of my commit after I've already pushed it to the upstream repository

user1050797
  • 261
  • 1
  • 3
  • 6
  • For an in-depth explanation of why pushing rewritten history can be scary (if anyone may have pulled from the upstream repository) see http://stackoverflow.com/questions/8448973/how-do-you-deal-with-a-public-repository-that-has-already-been-rebased/8449701#8449701 – Cascabel Dec 12 '11 at 20:35

2 Answers2

29

You will have to amend the commit ( git commit --amend --author="New Author Name <email@address.com>") on your local repository and force push- git push -f the change ( rewriting history is generally a bad practice once you have pushed upstream ).

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 3
    After I do this, instead of "wrongname committed", it now says "rightname authored and wrongname committed" in github – Kip May 04 '18 at 20:44
  • 1
    @Kip This was likely due to having the wrong name configured `user.name` and `user.email` (which is probably the source of the problem in the original mistaken commit). `git commit --amend --author "New Author Name "` The above changes the author, but uses your configured user / email as the committer. If you want to override the configured user / email, then: `git -c user.name="New Author Name" -c user.email=email@address.com commit --amend --reset-author` See the following for more info: https://gist.github.com/albertodebortoli/b2a6c3ebe82d9c13fe77 – willbush Jun 09 '21 at 04:23
15

Another complete solution.

In case you got multiple git-push done without realizing that the commits went with a different email account. now you need to change that. here is the command I have used to transform all my previous commit with a different email to the new email id.

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='yourname'; GIT_AUTHOR_EMAIL='youremail@example.com'; GIT_COMMITTER_NAME='yourname'; GIT_COMMITTER_EMAIL='youremail@example.com';" HEAD;
Community
  • 1
  • 1
Tarandeep Singh
  • 1,322
  • 16
  • 16
  • 2
    lol at the "Note" about please changing to use your own details.. :) – AO_ May 03 '17 at 11:39
  • 3
    A version of this also on GitHub support pages: https://help.github.com/articles/changing-author-info/ – Kip May 04 '18 at 21:02
  • 1
    Not recommended unless you know what you are doing! – pors May 04 '21 at 16:49
  • I think it is worth pointing out here that this changes the entire commit history. It is probably not what you want. – starfry May 23 '23 at 09:21