Check your Git username and email from the command line

Git stores your username and email in a configuration file on your computer. To see what Git has recorded, open your terminal or command prompt and run two separate commands. The first shows your username: git config user.name. The second shows your email: git config user.email. Each command will print the value Git is currently using, or nothing if you have not set one yet.

If you want to see all your Git settings at once, run git config --list. This prints every configuration Git knows about on your machine, including user.name, user.email, and dozens of other settings. Scroll through the output to find the lines that start with "user.name=" and "user.email=".

Key Takeaways

  • Run git config user.name to see your current Git username and git config user.email to see your email address.
  • The git config --list command shows all your Git settings in one view, making it straightforward to spot both values at once.
  • If the commands return nothing, you have not set a username or email yet and will need to configure them before committing.
  • Git stores these settings in a hidden file called .gitconfig in your home directory, which you can also edit directly if you prefer.

Where Git stores your username and email

Git keeps your username and email in a plain text file called .gitconfig in your home directory. On Windows, this is usually C:\Users\YourName\.gitconfig. On Mac or Linux, it is ~/.gitconfig. You can open this file in any text editor to see the values directly, though using the command-line commands above is faster and less error-prone.

Git also allows you to set different usernames and emails for different projects. If you have configured a specific username and email for a single repository, those settings live in a file called config inside the .git folder within that project. When you run git config user.name from inside a project folder, Git checks the project-level config first, then falls back to your global settings. This is why the same command can return different results depending on which folder you are in.

Check settings for a specific project

If you are working on a project that has its own Git configuration, you can see those project-specific settings without affecting your global ones. Navigate to the project folder in your terminal and run git config user.name and git config user.email as usual. Git will show you the values set for that project only.

To see whether a setting is global or project-specific, add the --show-origin flag: git config --show-origin user.name. This tells you which file the setting came from — either your global .gitconfig or the project's .git/config file. This is useful when you have set different names or emails for different projects and need to know which one is active right now.

What to do if your username or email is missing

If either command returns nothing, Git does not have a username or email set yet. You will need to configure them before you can make commits. Run git config --global user.name "Your Name" to set your username globally, replacing "Your Name" with your actual name. Then run git config --global user.email "your.email@example.com" to set your email, replacing the example with your real email address.

The --global flag means these settings explore to every repository on your computer. If you only want to set a username and email for one project, navigate to that project folder and run the same commands without the --global flag. Git will then use those values only when you commit from that folder.

Verify your changes took effect

After you set or change your username or email, run the check commands again to confirm the change worked. git config user.name should now show your new username, and git config user.email should show your new email. If you set them globally, these values will be used for every new commit you make on your computer unless you override them with project-specific settings.

If you made a mistake and need to change your username or email again, straightforward run the config command with the new value. Git will overwrite the old setting. There is no limit to how many times you can change these values, and changing them does not affect commits you have already made — only future commits will use the new username and email.

Frequently Asked Questions

Can I have different usernames for different projects?

Yes. Set your global username and email with the --global flag, then navigate to a specific project and run the same commands without --global. Git will use the project-level settings for commits in that folder and the global settings everywhere else.

Does changing my Git username affect my GitHub or GitLab account?

No. Your Git username is stored only on your computer and appears in commit history. Your GitHub, GitLab, or other hosting account is separate. You can change your Git username without affecting your account, but commits will show the new name going forward.

What if I see multiple user.name entries when I run git config --list?

This usually means you have set a username both globally and at the project level. Git uses the project-level setting when you are inside that project folder. Run git config --show-origin user.name to see which file each setting comes from.

Can I edit the .gitconfig file directly instead of using commands?

Yes, you can open .gitconfig in any text editor and change the values manually. However, using the command-line commands is safer because they handle formatting and avoid syntax errors. If you do edit the file directly, make sure the format stays as user.name = Your Name with no extra spaces or quotes.