Git uses your email address to associate commits with an identity.

The git config command can be used to change your Git configuration, including your email address. It takes two arguments:

  • The setting you want to change--in this case, user.email.
  • Your new email address, for example, me@here.com

For example:

git config user.email "me@here.com"
# Set a new email address
git config user.email
# Verify the setting
# me@here.com

You can also provide a special --global flag, which makes your email address the same across every local Git repository on your computer. For example:

git config user.email --global "me@here.com"
# Sets your email address across every local Git repository

Troubleshooting

Commits on GitHub aren't linking to my account

Make sure that email address associated with your GitHub account is the same email address used by Git. It may take some time for old commits to fall out of GitHub's cache, but any new commits should link up immediately. You should also verify your email address on GitHub.

New commits aren't using the right email

If git config user.email reports the correct email address for the repository you're viewing, but your commits are using the wrong email address, your environment variables may be overriding your email address.

Make sure you have not set the GIT_COMMITTER_EMAIL or GIT_AUTHOR_EMAIL variables. You can check their values with the following command:

echo $GIT_COMMITTER_EMAIL
# prints the value of GIT_COMMITTER_EMAIL
echo $GIT_AUTHOR_NAME
# prints the value of GIT_AUTHOR_EMAIL

If you notice a different value, you can change it like so:

GIT_COMMITTER_EMAIL=me@here.com
GIT_AUTHOR_EMAIL=me@here.com

My old commits still have my old email address

Changing your email address in Git only affects commits that you make after your change.

To rewrite your old commits, you can use git filter-branch to change the repository history to use your new email address.

Warning: If you're collaborating on a repository with others, it's considered bad practice to rewrite published history. You should only do this in an emergency.

Further reading