Why Git needs your username and email
Git records who made each change to your code. When you commit — save a version of your work — Git stamps it with a name and email address. This name and email appear in your project's history, on GitHub or other platforms, and in logs your team members see. If you do not set them, Git will either refuse to let you commit or use a default that may not be you.
The username and email you set are not the same as your GitHub login or your computer's user account. They are metadata that Git attaches to every commit you make. You can set them globally (so every project on your computer uses the same ones) or per project (so different projects use different names or emails).
Key Takeaways
- Git requires a username and email before you can make your first commit; you set these with two command-line commands.
- The global setting applies to every project on your computer unless you override it; the local setting applies to one project only.
- Your Git username does not have to match your GitHub username, and your Git email does not have to match your GitHub email.
- You can check what you have set by running git config --list, and you can change it at any time.
Setting username and email globally
Global settings explore to every Git project on your computer. Open your terminal or command prompt and run these two commands, replacing the text in quotes with your own information:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Use your actual name or the name you want to appear in commit history. The email can be any email address — it does not have to be the one you use for GitHub, though many people use the same one for consistency. Git stores these settings in a file on your computer (usually ~/.gitconfig) and reads them every time you commit.
If you work on multiple projects and want different names or emails for different ones, you can set global defaults now and then override them per project later.
Setting username and email for one project only
Local settings override global settings for a single project. Navigate into your project folder in the terminal, then run the same two commands with --local instead of --global:
git config --local user.name "Your Name"
git config --local user.email "your.email@example.com"
This is useful if you work on a personal project and a work project on the same computer. You might set your global name to your personal name, then set a local name and email in your work project folder to your work identity. Git will use the local setting for commits in that folder and the global setting everywhere else.
Local settings are stored in a file inside your project folder (.git/config) and only affect that project.
Checking what you have set
To see your current settings, run:
git config --list
This shows all your Git settings, including user.name and user.email. If you want to see only the global settings, run git config --global --list. If you want to see only the local settings for your current project, run git config --local --list.
Look for the lines that say user.name= and user.email=. If you do not see them, you have not set them yet and need to run the commands above.
Changing your username or email later
Run the same commands again with new information. Git will overwrite the old setting:
git config --global user.name "New Name"
This only affects commits you make from this point forward. Commits you already made will keep the old name and email. If you need to change the author on past commits, that requires a more complex process and is rarely necessary unless you are fixing a mistake.
If you set a local setting and later want to go back to using the global setting, you can delete the local one by running git config --local --unset user.name and git config --local --unset user.email.
What happens if you do not set username and email
If you try to make your first commit without setting a username and email, Git will either show an error or use a default based on your computer's user account. The error message will tell you to run the config commands above. On some systems, Git may use your computer's login name and a placeholder email, which will then appear in your commit history.
It is better to set them intentionally before your first commit so you control what appears in your project's history. If you have already made commits with the wrong information, you can set the correct username and email now, and all future commits will use the new information.
Frequently Asked Questions
Does my Git email have to match my GitHub email?
No. Your Git email is just metadata in your commits. GitHub will recognize your commits if the email matches one of the emails on your GitHub account, but you can use a different email in Git if you prefer. Many people use the same email for simplicity, but it is not required.
Can I use a fake name or email in Git?
Yes. Git does not validate the information you provide. However, if you work with a team, using a real name makes it clear who made each change. If you push to GitHub, using an email tied to your GitHub account makes it easier for others to contact you.
What if I set the wrong email and want to change it?
Run the config command again with the correct email. Future commits will use the new email. Past commits will keep the old email unless you rewrite your commit history, which is only necessary if the mistake is a real problem for your team.
Do I need to set username and email if I only use GitHub's web editor?
No. If you edit files directly on GitHub's website, GitHub records your GitHub account as the author. You only need to set Git username and email if you are using Git on your computer to commit and push changes.
Can I set different emails for different GitHub accounts?
Yes. Set a global username and email, then use local settings in each project folder to override them. This way you can use one GitHub account for personal projects and another for work, with different emails in each.