How to Configure Git Username and Email Address

Updated on

2 min read

Set Git Username and Email Address

Git is a distributed version control system that helps developers and engineers keep track of changes they make to their code.

The first thing you should do before starting to use Git on your system is to configure your Git username and email address. Git associates your identity with every commit you make.

Git allows you to set a global and per-project username and email address. You can set or change your git identity using the git config command. The changes made will only apply to future commits. The name and email associated with the commits you made before the change are unaffected.

Setting Global Git Username and Email

The global git username and email address are associated with the commits on all repositories on your system that don’t have repository-specific values.

To set your global commit name and email address, run the git config command with the --global option:

git config --global user.name "Your Name"git config --global user.email "youremail@yourdomain.com"

Once done, you can verify that the information is correctly set by executing the following command:

git config --list
user.name=Your Name
user.email=youremail@yourdomain.com

The command saves the values in the global configuration file, ~/.gitconfig:

~/.gitconfig
[user]
    name = Your Name
    email = youremail@yourdomain.com

You can also edit the file with your text editor, but it is recommended to use the git config command.

Setting Git Username and Email for a Single Repository

Sometimes, you may need to use a different username or email address for a specific repository. In that case, to set the identity, run the git config command without the --global option from within the repository directory.

Let’s assume you want to set a repository-specific username and email address for a repository located in the ~/Code/myapp directory. First, switch the repository root directory:

cd ~/Code/myapp

Set a Git username and email address:

git config user.name "Your Name"git config user.email "youremail@yourdomain.com"

Verify that the changes were made correctly:

git config --list
user.name=Your Name
user.email=youremail@yourdomain.com

The repository-specific settings are stored in the .git/config, located in the root directory of the repository.

Conclusion

The Git username and email address can be set with the git config command. The values are associated with your commits.

If you are new to Git, read the Pro Git book , which is an excellent resource for learning about how to use Git.

Leave a comment below if you hit a problem or have feedback.