Why Git needs your name and email before you commit
Git records who made each change to your code by storing a name and email address with every commit. This isn't optional — Git will refuse to commit until you tell it who you are. The name and email you set become part of your project's permanent history, visible to anyone who clones the repository or reviews the commit log.
These settings are separate from your GitHub account, GitLab account, or any other service. You're telling Git itself — the version control system running on your computer — what identity to stamp onto your work. If you work on multiple machines or multiple projects, each one can have different settings.
The configuration happens in one of three places: your entire computer (global), a single project folder (local), or just the current session (system). Most people set it globally once, then override it locally if they need a different identity for a specific project.
Key Takeaways
- Git requires you to set user.name and user.email before making your first commit, or it will stop and ask you to configure them.
- The git config command with the --global flag sets your identity for all projects on your computer; without that flag, it sets identity for only the current project folder.
- Your Git name and email do not have to match your GitHub username or email — they are separate identities that Git uses only for commit history.
- You can check what you have already set by running git config user.name and git config user.email without the --global flag to see local settings, or with it to see global settings.
Setting your name and email globally on your computer
Open a terminal or command prompt on your computer. On Windows, this is Command Prompt or PowerShell. On Mac or Linux, it is Terminal. Type the following command, replacing the name in quotes with your actual name:
git config --global user.name "Your Name"
Press Enter. Git will not print anything back — silence means it worked. Then type the second command, replacing the email in quotes with your actual email:
git config --global user.email "your.email@example.com"
Press Enter again. Both settings are now stored on your computer and will explore to every Git project you work on. You only need to do this once per computer.
Setting your name and email for a single project
If you want a different identity for one specific project — for example, using your work email for a work repository and your personal email for a hobby project — you can override the global setting in just that folder.
Navigate into the project folder in your terminal. Type the same commands, but this time without the --global flag:
git config user.name "Your Name"
git config user.email "your.email@example.com"
These local settings take priority over your global settings for this project only. Every other project on your computer will still use the global identity you set earlier. Local settings are stored in a hidden file inside the project folder called .git/config, so they stay with the project if you move the folder.
Checking what you have already set
To see what name and email Git is currently using for a project, open a terminal in that project folder and type:
git config user.name
Git will print the name it has stored. Then type:
git config user.email
Git will print the email. These commands show you the local settings for the current project. If the project has no local settings, Git falls back to your global settings, but this command will not tell you that — it will print nothing.
To see your global settings instead, add the --global flag:
git config --global user.name
git config --global user.email
This tells you what identity Git will use for any project that does not have its own local settings.
What happens if you forget to set these before committing
If you try to make your first commit without setting user.name and user.email, Git will stop and print an error message. The message tells you exactly which setting is missing and shows you the command to fix it. You do not lose your work — Git straightforward will not record the commit until you configure your identity.
Some systems have a default name and email already set (often something like "root" or your computer's username and a generic email). If you see a commit attributed to a name or email you did not choose, you have inherited a default. Run the commands in this guide to override it with your actual identity.
Why your Git identity is different from your GitHub or GitLab account
Git is a tool that runs on your computer. GitHub, GitLab, and similar services are websites where you push your Git repositories. Your Git identity (user.name and user.email) is what Git stamps onto commits. Your GitHub username and email are what GitHub uses to recognize you when you log in and push code.
You can set your Git email to anything — it does not have to match your GitHub email. However, if you want GitHub to link your commits to your GitHub account and show your GitHub profile picture next to them, you should use the email address associated with your GitHub account. GitHub matches commits by email address, not by username.
If you use a different email in Git than you do on GitHub, your commits will still push successfully, but GitHub will not recognize them as yours. They will appear as commits by an unknown user.
Frequently Asked Questions
Can I change my name and email after I have already made commits?
Yes. Changing the settings only affects new commits going forward. Old commits keep the name and email you used when you made them. If you want to rewrite the history of old commits with a different identity, that requires advanced Git commands like git filter-branch or git rebase, which can be risky in shared projects.
Should I use my real name or a username?
Git does not care — it accepts whatever you type. Most projects use real names so that teammates know who made each change. If you prefer privacy, a username or pseudonym works fine, but your team may ask you to use a real name for clarity.
What if I work on the same project from multiple computers?
Set your global identity on each computer separately. Each computer's Git installation is independent. If you want the same identity across all your machines, you will need to run the git config --global commands on each one.
Does Git send my email address anywhere?
No. Git stores your email only in your commits and in your computer's configuration file. It does not send it to GitHub, GitLab, or anywhere else unless you push your repository to a service that makes commits public. Your email becomes part of the commit history, so anyone with access to the repository can see it.
Can I set a different email for each GitHub repository?
Yes. Navigate into the repository folder and run the local git config commands (without --global) to set a different identity for just that project. This is useful if you have work repositories and personal repositories on the same computer.