DEV Community

Daniel Felix
Daniel Felix

Posted on • Originally published at danielfelix.in

How to Configure Git Username and Email Address

Git is a distributed version control system that’s being used by most software teams today. The first thing you should do after installing Git on your system is to configure your git username and email address. Git associate 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. Changes only affect future commits. The name and email associated with the commits you made prior to the change are not affected.

Setting Global Git Username and Password

The global git username and password 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"
git config --global user.email "youremail@yourdomain.com"
Enter fullscreen mode Exit fullscreen mode

Once done, you can confirm that the information is set by running:

git config --list
Enter fullscreen mode Exit fullscreen mode
user.name=Your Name
user.email=youremail@yourdomain.com
Enter fullscreen mode Exit fullscreen mode

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

~/.gitconfig

[user]
    name = Your Name
    email = youremail@yourdomain.com
Enter fullscreen mode Exit fullscreen mode

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

Setting Git Username and Password for a Single Repository

If you want to use a different username or email address for a specific repository, run the git config command without the --global option from within the repository directory.

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

cd ~/Projects/myapp
Enter fullscreen mode Exit fullscreen mode

Set a Git username and email address:

git config user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode

Verify that the changes were made correctly:

git config --list
Enter fullscreen mode Exit fullscreen mode
user.name=Your Name
user.email=youremail@yourdomain.com
Enter fullscreen mode Exit fullscreen mode

The repository-specific setting are kept in the .git/config file under 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.

Top comments (0)