How to Configure Git Username and Email Address

This guide explains how to configure your Git username and email address. It covers setting global values for all repositories and repository-specific values for individual projects. Properly configuring these settings ensures your commits are associated with the correct identity.

Git
How to Configure Git Username and Email Address

Contents


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

Before you start using Git on your system, it’s essential to configure your Git username and email address. Git associates your identity with every commit you make.

Setting Global Git Username and Email

The global git username and email address are associated with 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"

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

git config --list

This will output:

user.name=Your Name
user.email=youremail@yourdomain.com

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

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

You can also edit this 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, you can set the identity per repository by running 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, navigate to the repository directory:

cd ~/Code/myapp

Then, set the Git username and email address:

git config user.name "Your Name"

Verify that the changes were made correctly:

git config --list

This will output:

user.name=Your Name
user.email=youremail@yourdomain.com

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

Conclusion

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

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

Leave a comment below if you encounter any issues or have feedback.


Related Tutorials:

ad ad