Configure username and email for Git commits
Changing the username or mail address in Git is an easy task. All you need to do is to enter a command in your terminal. But before we start you should know that you can set up a username/email globally and/or for any single repository. This is pretty handy if you work for different organizations. For instance, you can work with the global values for your private projects and set a different mail address for projects where you have to use another mail. If you want you can also change the name in that specific repository. First I show you how to change the global configuration. Open the terminal and set the name and email by using the following commands:
git config --global user.name "Denis Zygann"
git config --global user.email name@provider.com
This configuration sets the username and the mail address for all repositories on your local machine. You can find the name and email properties for the global configuration in the ~/.gitconfig
file.
To override the global configuration for a specific repository, you need to go to the working directory of your repository. Then you can change the name and mail by using the following commands:
cd ~/path/to/repogit config user.name "Kermit the Frog"
git config user.email "alias@provider.com"
The repository properties are stored in the .git/config
file. It doesn’t matter which OS do you use. The commands are working for Windows, Mac and Linux.
Often you have to do this step when you install git
for the first time. A message came up and print out the global commands above. After you have changed the properties you can also verify them by using the list
option:
git config --list
If you are interested in more detailed information about the configuration check out the git documentation.