How to Set Git Username and Email with git config

By 

Updated on

4 min read

Set Git Username and Email

Git uses your username and email address to identify each commit you make.

This article explains how to set or change your Git username and email with the git config command, both globally and for a single repository.

These changes apply only to future commits, and the name and email stored in existing commits do not change.

Quick Reference

CommandDescription
git config user.nameShow current username
git config user.emailShow current email
git config --get user.nameShow current username (resolved)
git config --get user.emailShow current email (resolved)
git config --list --show-originShow all config with sources
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config user.name "Name"Set repository username
git config user.email "email"Set repository email
git config --global --editEdit global config file
git config --global --unset user.nameRemove global username

Checking Your Current Git Configuration

Before setting or changing your Git identity, you may want to check what’s currently configured.

To see your current username and email:

Terminal
git config user.name
git config user.email

To see the current values (after applying global and local settings), use:

Terminal
git config --get user.name
git config --get user.email

To see all Git configuration values and where they come from:

Terminal
git config --list --show-origin
output
file:/home/user/.gitconfig      user.name=Your Name
file:/home/user/.gitconfig      user.email=youremail@yourdomain.com
file:.git/config                user.email=work@company.com

The --show-origin flag shows whether each setting comes from the global config (~/.gitconfig), system config (/etc/gitconfig), or local repository config (.git/config).

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:

Terminal
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:

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

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

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

You can also edit the file directly, but using the git config command is usually easier and less error-prone.

If you prefer editing the file directly, open it with:

Terminal
git config --global --edit

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. For example, using a personal email for open-source projects and a work email for company repositories.

To set the identity for a single repository, run the git config command without the --global option from within the repository directory.

Suppose you want to set a repository-specific username and email for a repository in ~/Code/myapp. First, switch to the repository root directory:

Terminal
cd ~/Code/myapp

Set the Git username and email address:

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

Verify that the changes were made correctly:

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

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

Automatic Identity Switching with Conditional Includes

If you work on multiple projects that require different identities, you can configure Git to automatically switch based on the repository location.

Add a conditional include to your ~/.gitconfig:

~/.gitconfigconf
[user]
    name = Personal Name
    email = personal@example.com

[includeIf "gitdir:~/Work/"]
    path = ~/.gitconfig-work

Then create a ~/.gitconfig-work file with your work identity:

~/.gitconfig-workconf
[user]
    name = Work Name
    email = work@company.com

Now any repository under ~/Work/ will automatically use your work identity, while all others use your personal identity. This approach works similarly to .gitignore files, where Git applies configuration based on context.

Removing a Git Configuration Value

To remove a configuration value, use the --unset option:

Terminal
# Remove global username
git config --global --unset user.name

# Remove repository-specific email
git config --unset user.email

Conclusion

You can set or change your Git username and email with git config, either globally or for a single repository. If you manage multiple identities, conditional includes are the cleanest way to switch automatically based on repository location.

If you are new to Git, the Pro Git book is a solid next read.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page