How to Change Author Name and Email of Commits?

How can i change the author name and email settings globally for future commits? Is there also a way to just do this per repository? Can i also change this information on past commits?  

3 Likes

Great question, thanks for asking!

These are all pretty common questions that we have help pages for:

I hope that helps :grinning:

11 Likes

Just the information i was looking for. Thanks!

3 Likes

@lee-dohm wrote:

Great question, thanks for asking!

 

These are all pretty common questions that we have help pages for:

 

 

I hope that helps :grinning:

@teazateazza It looks like you were maybe trying to respond here, but only the quote of @lee-dohm’s comment came through. You might want to edit your post to make sure your whole message is shared. Thanks!

Related question: What happens when we lose access to an email address (for example, when changing employers) that our previous commits were associated with. It looks like all the commit and contribution history is lost. Years worth of history. This is super inconvenient.

The second option you listed below doesn’t work since most authors don’t own the repos, and even if they did, rewriting git history is not a good practice.

GitHub knows that all these commits were made by the author, even if that author does not get to keep his/her email address forever. So ideally GitHub should be able to still associate those commits to the correct author.

Is there anyway to recover history? Thanks for your help.

3 Likes

You don’t have to remove an email address from the list of email addresses in your GitHub account simply because you’ve lost access to it. You can leave it associated to your account to maintain a connection with your old history. You should make certain that you always have access to at least one email address associated with your GitHub account for password resets, email notifications and the like. But you don’t have to remove an email address just because it isn’t current.

The way the system currently works, associating commits by email address, is the best balance between multiple needs. There are also times that people want to divorce themselves from work they did in the past and removing the email address from the list of addresses that apply is an easy way to do that. If we used some other way of tracking contributions, removing unwanted items from your history would be a much more complex affair.

2 Likes

I applied for an account with the username BobMarq and then accidentally entered a mispelled e-mail address

The second link isn’t working for me.

Has it been removed on purpose?

If not, could you please update the link or post a new working one?

This is the most recent version I can find working

This did not work for me. After I executed the script I got the following:

WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Rewrite 9e53679d...
...
WARNING: Ref 'refs/heads/master' is unchanged
WARNING: Ref 'refs/heads/wiki' is unchanged

Then I executed:
git push --force --tags origin 'refs/heads/*'

And got the following message:
Everything up-to-date

When I reloaded the repository on Github, no changes took effect.

Anyone could suggest what has to be done? Thanks!

Apparently, in my case email address was used as either GIT_COMMITTER_NAME or GIT_AUTHOR_NAME and that’s why the script was not working. That probably happened when I was importing the source code from google code a while ago.

Extending if statement conditions to:
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] || [ "$GIT_COMMITTER_NAME" = "$OLD_EMAIL" ]

and

if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] || [ "$GIT_AUTHOR_NAME" = "$OLD_EMAIL" ]

made it work.

1 Like

I was not aware of this and recently cleaned up my account information (as you do with many accounts when your email addresses change) and just realized that I thus lost 5 years worth of work associated with those old addresses.
Is there any way to undo deleting old email addresses (they don’t exist any more, so simply re-adding wouldn’t work)? I’m still the admin of the repositories in question, I just don’t want to rewrite history by changing the commits.

Maybe a straightforward solution to this whole issue would be to add an option in the settings for users to choose whether to list contributions by email address or account. It doesn’t seem likely to me that the majority of users wish to disassociate themselves from previous work, so association-by-account seems the more reasonable default. In contrast kicking past contributions off your account should be an active choice and not something that simply happens as a by-product of basic account maintenance.