To set your git config username and email, run git config --global user.name "Your Name" and git config --global user.email "[email protected]" once. Git stores both values in every commit you make afterwards.
Replace the name and address with your own in every command below. The commands are the same on Windows (Git Bash, PowerShell, Command Prompt), macOS and Linux.
How to set your name and email globally
git config --global user.name "John Doe"
git config --global user.email [email protected]
The Pro Git book says to do this when you first install Git, because "every Git commit uses this information, and it's immutably baked into the commits you start creating". With --global you need to do it only once: Git uses these values for your user account on that machine, in all repositories.
Quote the name if it has spaces. The email address needs no quotes unless your shell treats a character in it specially.
How to check your git config username and email
Print one value:
git config user.name
git config user.email
Example output:
John Doe
[email protected]
Without --global, this shows the value Git will actually use in the current folder, after all config files have been combined. If a key is not set anywhere, the command prints nothing and exits with code 1.
To see where a value comes from:
git config --show-origin user.email
Example output (the path is anonymised):
file:/home/alex/.gitconfig [email protected]
To list every setting with its file, use git config --list --show-origin. If the same key appears more than once, the last line is the one that wins.
How to change your username or email
Run the same command with the new value. It replaces the old one:
git config --global user.email [email protected]
This changes only future commits. The name and email are written into each commit when it is created, so existing commits keep the old identity. GitHub states the same thing: "Any commits you made prior to changing your commit email address are still associated with your previous email address." To fix the author of the most recent commit only, see how to change a Git commit message, which covers amending a commit.
You can also edit the file directly. Open it with git config --global --edit and look for a [user] section:
[user]
name = John Doe
email = [email protected]
How to use a different email for one repository
Go into the repository and run the commands without --global:
cd path/to/work-project
git config user.name "John Doe"
git config user.email [email protected]
Without a scope option, git config writes to the repository's own file, .git/config. That is the local scope, and it overrides the global one. The Pro Git book describes the order: each level overrides the one before it, so .git/config beats your user-level file, which beats the system-wide file.
| Scope | Option | File | Applies to |
|---|---|---|---|
| System | --system | [path]/etc/gitconfig | Every user on the machine (needs administrator rights to edit) |
| Global | --global | ~/.gitconfig or ~/.config/git/config | All your repositories |
| Local | --local (the default) | .git/config | That one repository |
How to use a work email for a whole folder of repositories
Setting the email repository by repository is easy to forget. Git can include extra config only for repositories under a certain folder, using includeIf with a gitdir: condition. In your global config (~/.gitconfig):
[user]
name = John Doe
email = [email protected]
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
Then create ~/.gitconfig-work:
[user]
email = [email protected]
Every repository whose .git directory sits under ~/work/ now uses the work email, and everything else uses the personal one. The git-config documentation says that a pattern ending in / gets ** added automatically, so the whole folder tree matches. Put the includeIf block after the [user] section, because later values override earlier ones.
How to stop Git guessing your identity
If you have not set a name and email, Git may try to guess them from your system. Guessed addresses are often wrong. To make Git refuse instead, set user.useConfigOnly in the global config:
git config --global user.useConfigOnly true
The git-config documentation describes this for people with several email addresses: with the option set to true in the global config along with a name, "Git will prompt you to set up an email before making new commits in a newly cloned repository". It defaults to false. This pairs well with leaving the global user.email unset and setting it per repository.
Which email should you use with GitHub?
GitHub matches commits to your account by the commit email address, so use an address that is added to your GitHub account. GitHub's docs say that, to keep your email private for web-based operations, you select Keep my email addresses private in your email settings. For commits made from the command line, set user.email to your GitHub-provided noreply address. As of November 2026, GitHub documents two formats:
- Accounts created after July 18, 2017:
[email protected] - Older accounts that enabled privacy before that date:
[email protected]
Your ID-based address is shown in your GitHub email settings. Other hosts such as GitLab and Bitbucket have their own rules, so check their documentation.
Name and email are not your login
user.name and user.email only label commits. They are not credentials, and Git does not check them: anyone can set any name and email. Whether you can push is decided by your password, token or SSH key. If a push is rejected, see fixing "Permission denied (publickey)" or setting up Git Credential Manager.
Also, user.name conventionally holds a personal name, not your account username. The git-config documentation notes that the name variables "conventionally refer to some form of a personal name" and points to credential.username if you want an authentication username.
Overriding the name and email for one command
The documentation says the config values can all be overridden by the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL and EMAIL environment variables. To make a single commit as someone else without touching any config file (Bash):
[email protected] [email protected] git commit -m "message"
In PowerShell, set $env:GIT_AUTHOR_EMAIL and $env:GIT_COMMITTER_EMAIL first, then run git commit.
If it still shows the wrong identity
- Run
git config --show-origin user.emailinside the repository. A local.git/configor anincludeIffile may be overriding the global value. - Check for the environment variables above:
echo $GIT_AUTHOR_EMAILin Bash, or$env:GIT_AUTHOR_EMAILin PowerShell. - Remember that old commits never change. Only commits made after the change use the new value.
- To remove a value, use
git config --global --unset user.email. Newer Git versions also acceptgit config unset --global user.email.
Frequently asked questions
- What is the difference between git config user.name and a GitHub username?
- They are unrelated settings. user.name is free text stored in each commit as the author and committer name, and Git conventionally expects a personal name. Your GitHub username is an account identifier used for authentication. GitHub links commits to your account by the commit email address, not by user.name.
- Does changing user.email rewrite my old commits?
- No. The name and email are stored inside each commit when it is created, so a new setting only affects commits you make afterwards. GitHub also states that commits made before you changed your commit email stay associated with the previous address.
- Where does git config --global store the name and email?
- In your user-level config file, either ~/.gitconfig or $XDG_CONFIG_HOME/git/config (which defaults to ~/.config/git/config). If both files exist, Git reads both, in that order. Run git config --global --list --show-origin to see which file holds the values.
- Can I set a different name or email for just one repository?
- Yes. Run git config user.name "Name" and git config user.email "address" inside that repository, without --global. The values go into .git/config and override the global ones for that repository only.