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. It takes two arguments:
- The setting you want to change--in this case,
user.name
. - Your new name, for example,
Billy Everyteen
To set your username for a specific repository, enter the following command in the root folder of your repository:
git config user.name "Billy Everyteen" # Set a new name git config user.name # Verify the setting Billy Everyteen
To set your username for every repository on your computer:
Navigate to your repository from a command-line prompt.
-
Set your username with the following command.
git config --global user.name "Billy Everyteen"
-
Confirm that you have set your username correctly with the following command.
git config --global user.name Billy Everyteen
To set your username for a single repository:
Navigate to your repository from a command-line prompt.
-
Set your username with the following command.
git config user.name "Billy Everyteen"
-
Confirm that you have set your username correctly with the following command.
git config user.name Billy Everyteen
Tip: You don't have to use your real name--any name works. Git actually associates commits by email address; the username is only used for identification. If you use your email address associated with a GitHub Enterprise account, we'll use your GitHub Enterprise username, instead of this name.
Troubleshooting
My name doesn't show up on GitHub Enterprise
If the email used in a commit matches a verified GitHub Enterprise user account, the account's username is used, instead of the username set by Git.
New commits aren't using the right name
If git config user.name
reports the correct username for the repository you're viewing,
but your commits are using the wrong name, your environment variables may be
overriding your username.
Make sure you have not set the GIT_COMMITTER_NAME
or GIT_AUTHOR_NAME
variables.
You can check their values with the following command:
echo $GIT_COMMITTER_NAME # prints the value of GIT_COMMITTER_NAME echo $GIT_AUTHOR_NAME # prints the value of GIT_AUTHOR_NAME
If you notice a different value, you can change it like so:
GIT_COMMITTER_NAME=Billy Everyteen GIT_AUTHOR_NAME=Billy Everyteen
My old commits still have my old username
Changing your username 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 username.
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.