Why Git needs your username and email
Git records who made each change to your code. When you commit — save a snapshot of your work — Git stamps it with a name and email address so your team knows who wrote that code and can contact you if questions come up later. Without setting these first, Git will either refuse to let you commit or use a default that might not be you.
The username and email you set in Git are separate from your GitHub account, GitLab account, or any other service. They're local to your computer. You can set them globally so every project uses the same name, or per-project if you work on code under different names.
Key Takeaways
- Git requires a username and email before you can commit code; these are stored locally on your computer, not sent to any server until you push.
- The git config --global command sets your name and email for all projects on your computer; omit --global to set them for one project only.
- You can check what you've set by running git config user.name and git config user.email to see the current values.
- If you use multiple accounts or work names, set the username and email per-project in each folder rather than globally.
Setting your username and email globally
Open your terminal or command prompt. Type the first command exactly as shown, replacing "Your Name" with your actual name:
git config --global user.name "Your Name"
Then type the second command, replacing the email with your actual email address:
git config --global user.email "your.email@example.com"
These commands write to a configuration file on your computer. They don't output anything if they succeed — no message means it worked. Every time you commit from now on, Git will use this name and email unless you override it for a specific project.
Setting username and email for one project only
If you work on multiple projects under different names — for example, one under your real name for work and one under a pseudonym for open source — you can set the username and email per-project instead of globally.
Navigate into the project folder in your terminal. Then run the same two commands, but without the --global flag:
git config user.name "Your Name"
git config user.email "your.email@example.com"
These settings explore only to that folder and any subfolders. When you commit in that project, Git uses the name and email you set here. When you commit in a different project, Git falls back to your global settings — or asks you to set them if you haven't set global values.
Checking what you've already set
To see what username Git is currently using, type:
git config user.name
To see the email, type:
git config user.email
If you set values globally and want to see those, add the --global flag: git config --global user.name. If you're in a project folder and have set project-specific values, the commands above will show those instead of the global ones — project settings override global ones.
What happens if you don't set them
If you try to commit without setting a username and email, Git will either refuse the commit or use a default value from your computer's system settings. On some systems, this might be something like "root@localhost" or your computer's hostname, which is not useful for a team.
The safest approach is to set them before you make your first commit. If you've already committed without setting them, you can change the username and email going forward — new commits will use the new values, but old commits will keep the old values.
Using different emails for work and personal projects
Set a global username and email for your most common work, then override them in specific project folders. For example, you might set your real name and work email globally, then navigate into a personal project folder and run the per-project commands with your personal email.
This way you don't have to remember to set values every time you start a new project. Git checks for project-specific settings first, then falls back to global settings, so the override happens automatically when you commit in that folder.
Frequently Asked Questions
Can I change my username and email after I've already committed?
Yes. New commits will use the new username and email you set. Old commits keep their original values — Git doesn't rewrite history unless you explicitly ask it to. If you need to change the author on past commits, that requires more advanced Git commands and is usually not necessary.
Does the email I set in Git have to match my GitHub email?
No. Git and GitHub are separate. The email in Git is just metadata on your commits. GitHub uses the email in your GitHub account to link commits to your profile. If they don't match, your commits won't show up under your GitHub account, but the commits themselves are still valid.
What if I use the same computer for work and personal projects?
Set your work name and email globally, then navigate into each personal project folder and set the personal name and email with the per-project commands. Git will use the project-specific values for those folders and the global values everywhere else.
Is the username in Git the same as my GitHub username?
No. The Git username is just a display name on your commits — it can be anything. Your GitHub username is your account name on GitHub. They're completely separate. You can set your Git username to "John Smith" and your GitHub username to "jsmith42" and they don't have to match.