56

I'm new to web development and GitHub. When I commit any changes, these changes are reflected on my GitHub repo under "unknown (author)". How do I change this to reflect my name/email address?

Thanks.

idlefingers
  • 31,659
  • 5
  • 82
  • 68
oxo
  • 4,343
  • 10
  • 32
  • 35
  • Related: [How do I change the author of a commit in git?](http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git). –  May 18 '14 at 17:16

4 Answers4

113
$ git config --global user.name "Scott Chacon"
$ git config --global user.email "schacon@gmail.com"
Ori
  • 4,132
  • 1
  • 25
  • 27
  • 11
    You can also omit the `--global` flag if you only want to modify those settings for a particular repository. If I recall, any repository-specific configuration settings will override any global settings. – CIFilter Feb 15 '11 at 18:44
21

Add something like this to a file called ~/.gitconfig (in your home directory):

[user]
    name = USERNAME
    email = EMAIL_ADDRESS

where USERNAME and EMAIL_ADDRESS are filled in appropriately

Lee Netherton
  • 21,347
  • 12
  • 68
  • 102
6

Note that starting Git 2.2 (Q3/Q4 2014), and commit 9830534 by Matthieu Moy (moy), you will be naturally guided to enter a user and email:

config --global --edit: create a template file if needed

When the user has no ~/.gitconfig file, git config --global --edit used to launch an editor on an nonexistant file name.

Instead, create a file with a default content before launching the editor.
The template contains only commented-out entries, to save a few keystrokes for the user. If the values are guessed properly, the user will only have to uncomment the entries.

Advanced users teaching newbies can create a minimalistic configuration faster for newbies.
Beginners reading a tutorial advising to run "git config --global --edit" as a first step will be slightly more guided for their first contact with Git.


If you put your GitHub username and email account in those settings, your commits will accurately reflect your GitHub account as the right author.

Note that the user.name and email are guessed and put in that /.gitconfig file, as per commit 8b27ff7:

commit: advertise config --global --edit on guessed identity

When the user has no user-wide configuration file, it's faster to use the newly introduced config file template than to run two commands to set user.name and user.email. Advise this to the user.

The old advice is kept if the user already has a configuration file since the template feature would not trigger in this case.

New advice:

Your name and email address were configured automatically based on your username and hostname.
Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file:"

git config --global --edit

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    This still works in 2022. Because VSCode is set as my default editor for some file types, it opened automatically into it and I was able to update my Author name. – Mark Sep 16 '22 at 14:44
1

Git uses your username to associate commits with an identity. The git config command can be used to change your Git configuration, including your username. Here is a good guide available: https://help.github.com/articles/setting-your-username-in-git/

Jishnu Dey
  • 129
  • 3
  • 6