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
For a printable quick reference, see the Git cheatsheet .
| Command | Description |
|---|---|
git config user.name | Show the configured username |
git config user.email | Show the configured email |
git config --global --get user.name | Show the global username only |
git config --local --get user.email | Show the repository email only |
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 |
git commit --amend --only --reset-author --no-edit | Fix the identity on the last commit |
Checking Your Current Git Configuration
Before setting or changing your Git identity, you may want to check what is currently configured.
To see your current username and email:
git config user.name
git config user.emailThese commands show the configured values Git finds after combining its configuration scopes, with repository settings taking precedence over global ones. The longer form git config --get user.name returns the same result. To check a particular scope, pair --get with --global or --local:
git config --global --get user.name
git config --local --get user.emailIf the second command prints nothing, no email is set in the repository’s local configuration. Run git config user.email to check whether another scope supplies one.
To find the file supplying the selected username, use --show-origin:
git config --show-origin --get user.nameTo 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 do not 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 --global --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 --local --listcore.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:yourname/myapp.git
user.name=Your Name
user.email=youremail@yourdomain.comThe --local flag limits the output to this repository. Without it, git config --list merges the system, global, and repository files into a single list, which makes it harder to see what the repository itself overrides.
The repository-specific settings are stored in .git/config, located in the root directory of the repository.
Fixing Commits Made with the Wrong Identity
Correcting your configuration does not touch commits that already exist. If you have just discovered that the last commit carries the wrong name or email, you can rewrite it so that it picks up your corrected settings.
git push --force-with-lease rather than --force.After correcting your configuration, run:
git commit --amend --only --reset-author --no-editThe --only option keeps other staged changes out of the amended commit. The --reset-author option sets the author name and email to the current committer identity and renews the author timestamp. The --no-edit option keeps the existing commit message instead of opening an editor.
If you need a specific author name and email rather than those in your configuration, pass them directly:
git commit --amend --only --author="Your Name <youremail@yourdomain.com>" --no-editGit stores two identities on every commit, the author and the committer. Both commands above change the author; the committer is always taken from your configuration at the moment you run the amend, which is why fixing your config first matters.
Confirm the result with git log
:
git log -1 --pretty="%an <%ae>"Your Name <youremail@yourdomain.com>The author line now shows the corrected identity.
Amending reaches only the most recent commit. To fix an older one, run git rebase -i HEAD~N, replacing N with the number of recent commits to include (for example, HEAD~3 for the last three). Mark the target commit as edit, run the amend command above, and then continue with git rebase --continue. The same cautions apply as when you change a commit message
.
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.emailFAQ
Does setting user.name and user.email log you in to GitHub or GitLab?
No. The user.name and user.email values only label your commits. They do not authenticate you to any remote. Authentication when you push or pull is handled separately, through SSH keys or a personal access token.
Why does Git ask for a username and password when you push?
That prompt is the remote server authenticating you, not your commit identity. Most hosts no longer accept your account password over HTTPS, so use a personal access token in place of the password, or use SSH keys
to avoid HTTPS credential prompts.
Can you set a password with git config?
No. git config does not store account passwords. It manages settings such as your identity, aliases, and editor. Credentials for remotes are held by a credential helper or your SSH agent, not in user.name or 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 is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page