Where Git Stores Your Username and Email
Git stores your username and email in a configuration file on your computer. When you commit code, Git automatically attaches this information to every change you make. You can view what Git has stored in three places: your global configuration (which applies to all your projects), your local configuration (which applies only to one project), or your system configuration (which applies to all users on the computer).
Most people work with the global configuration, which is the easiest to check and the one Git uses by default. Your username and email are plain text in a file called .gitconfig, located in your home directory. You do not need special permissions to read it — you just need to know where to look or what command to run.
Key Takeaways
- Run git config --global user.name and git config --global user.email in your terminal to see what Git has stored for you.
- If those commands return nothing, Git does not have your username and email set yet, and you will need to add them before making commits.
- Your global configuration file lives in your home directory as .gitconfig and you can open it in any text editor to see all your settings at once.
- Local configuration (set per project) overrides global configuration, so a project might use different credentials than your default.
Checking Your Global Username and Email
Open your terminal or command prompt and type this command exactly:
git config --global user.name
Press Enter. If Git has your username stored, it will print it on the next line. If nothing appears, Git does not have a username set. Repeat the process with your email:
git config --global user.email
Press Enter again. You will see your email address if it is set, or nothing if it is not. These two commands are the fastest way to check what you have configured. If both commands return values, you are done — Git knows who you are.
Opening Your Configuration File Directly
If you want to see all your Git settings at once instead of running two separate commands, you can open the configuration file itself. On Mac or Linux, open your terminal and type:
cat ~/.gitconfig
On Windows with PowerShell, type:
type $env:USERPROFILE\.gitconfig
The file will print to your screen. Look for the lines that say [user], name =, and email =. Your username and email will be on the lines when ready after those labels. If the file does not exist, Git has not stored any configuration yet.
You can also open the file in any text editor. On Mac or Linux, use nano ~/.gitconfig or open it through your file manager by showing hidden files (files starting with a dot are hidden by default). On Windows, navigate to your home directory and look for a file named .gitconfig — you may need to enable viewing hidden files in your folder settings.
Checking Configuration at the Project Level
A single project can have its own username and email that overrides your global settings. This is useful if you work on both personal and work projects and want different credentials for each. To see if a project has local configuration, navigate into that project's folder in your terminal and type:
git config --local user.name
If this returns a value, the project uses different credentials than your global settings. Check the email the same way:
git config --local user.email
Local configuration is stored in a file called config inside the hidden .git folder at the root of your project. You can open it the same way you would open the global configuration file, but you navigate to the project folder first.
What to Do If Your Configuration Is Empty
If both commands return nothing, Git does not have your username and email set. You need to add them before you can make commits. The process is straightforward: run these two commands, replacing the text in quotes with your actual name and email address.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Use your real name or the name you want to appear in your commit history. The email should be the one associated with your Git hosting service (GitHub, GitLab, Bitbucket, or another platform). After you run these commands, verify they worked by running the check commands again — you should now see your name and email printed back to you.
Understanding Why Git Needs This Information
Every time you commit code, Git records who made the change and when. This creates an audit trail so anyone looking at the project history can see who wrote each line of code and when it was added. The username and email you configure are what appear in that history. If you work with others on the same project, your commits will be distinguished from theirs by this information.
On platforms like GitHub or GitLab, the email you configure in Git should match the email on your account. This links your commits to your profile and shows your contribution graph correctly. If the email does not match, your commits may appear as coming from an unknown user even though you wrote them.
Frequently Asked Questions
Can I have different usernames for different projects?
Yes. Set your global username and email as your default, then navigate into any project folder and run the same commands with --local instead of --global. That project will use the local credentials instead. This is common when you work on both personal and work projects.
What if I see three different usernames when I check global, local, and system config?
Git checks configuration in this order: local (project-specific), global (your user account), then system (all users on the computer). The first one it finds is what it uses. If you have set credentials at all three levels, your local project settings override everything else.
Does my Git username have to match my GitHub username?
No. Your Git username is just text that appears in your commit history. Your GitHub username is your account name on GitHub. They can be different. However, the email in your Git configuration should match an email on your GitHub account for your contributions to be linked to your profile.
Can I change my username and email after I have already made commits?
Yes. Changing your configuration only affects new commits going forward. Old commits keep the username and email that was set when you made them. If you need to change the author information on past commits, that requires more advanced Git commands and is not necessary for most situations.