How to Set Git Username and Email with git config

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
| Command | Description |
|---|---|
git config user.name | Show current username |
git config user.email | Show current email |
git config --get user.name | Show current username (resolved) |
git config --get user.email | Show current email (resolved) |
git config --list --show-origin | Show 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 --edit | Edit global config file |
git config --global --unset user.name | Remove 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:
git config user.name
git config user.emailTo see the current values (after applying global and local settings), use:
git config --get user.name
git config --get user.emailTo see all Git configuration values and where they come from:
git config --list --show-originfile:/home/user/.gitconfig user.name=Your Name
file:/home/user/.gitconfig user.email=youremail@yourdomain.com
file:.git/config user.email=work@company.comThe --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:
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:
git config --listuser.name=Your Name
user.email=youremail@yourdomain.comThe command saves the values in the global configuration file, ~/.gitconfig:
[user]
name = Your Name
email = youremail@yourdomain.comYou 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:
git config --global --editSetting 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:
cd ~/Code/myappSet the 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 --listuser.name=Your Name
user.email=youremail@yourdomain.comThe 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:
[user]
name = Personal Name
email = personal@example.com
[includeIf "gitdir:~/Work/"]
path = ~/.gitconfig-workThen create a ~/.gitconfig-work file with your work identity:
[user]
name = Work Name
email = work@company.comNow 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:
# Remove global username
git config --global --unset user.name
# Remove repository-specific email
git config --unset user.emailConclusion
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 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