Why Git needs your username and email
Git records who made each change to a project's code. When you commit — save a version of your work — Git stamps it with a name and email address so other people (or your future self) know who wrote that code. Without this setup, Git will refuse to let you commit, or it will use a default name that does not identify you.
This is different from your GitHub username or any online account. This is a local setting on your computer that Git uses every time you save work. You set it once, and Git remembers it for all your projects unless you change it later.
Key Takeaways
- Git requires a username and email address configured on your computer before you can commit code.
- The fastest way is to open your terminal or command prompt and run two short commands with your name and email.
- Use the --global flag to set these once for all projects, or leave it out to set them for one project only.
- You can verify your settings are saved by running a command that displays what Git currently has stored.
- If you use multiple Git accounts, you can override the global settings for individual projects.
Setting username and email globally on your computer
Open your terminal (on Mac or Linux) or Command Prompt or PowerShell (on Windows). Type this command, replacing "Your Name" with your actual name:
git config --global user.name "Your Name"
Press Enter. Git will not print a confirmation — silence means it worked. Now type the second command, replacing the email with your actual email address:
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. The --global flag tells Git to save these settings in your user account's configuration file, not just in one project folder.
Checking what you just set
To confirm Git has your settings, type this command:
git config --global user.name
Git will print back the name you entered. Do the same for email:
git config --global user.email
If either command prints nothing, or prints something different from what you typed, run the setup commands again. Common mistakes are forgetting the quotes around your name, or mistyping the email address.
Setting username and email for one project only
If you work on multiple projects and need different names or emails for each one, you can override the global settings for a single project. Navigate into that project's folder in your terminal, then run the same commands without the --global flag:
git config user.name "Different Name"
git config user.email "different.email@example.com"
Now when you commit in that folder, Git will use these settings instead of the global ones. Other projects will still use your global settings. This is useful if you have a work account and a personal account, or if you collaborate on a project where the team expects commits under a shared name.
What happens if you forget to set these
If you try to commit without setting a username and email, Git will stop you with an error message. The message will tell you to run the config commands — it is Git's way of saying "I need to know who you are before I save this."
On some systems, Git may use a default name like "root" or your computer's login name, which is not helpful for identifying who actually wrote the code. Setting these values yourself prevents confusion later, especially if other people are reading your commit history.
Changing your settings later
You can change your username or email at any time by running the same commands with new values. The new settings will explore to all future commits. Past commits will keep the name and email you had when you made them — changing your settings now does not rewrite history.
If you need to change the author name on commits you have already made, that is a more advanced task that requires rewriting Git history. For most people, setting the correct name and email before you start committing is the simplest approach.
Frequently Asked Questions
Does my Git email have to match my GitHub email?
No. Your Git email is a local setting on your computer. Your GitHub email is your account on GitHub's website. They can be different. However, if you want GitHub to recognize your commits and link them to your GitHub profile, you should use an email address that matches one of the emails on your GitHub account.
Can I use a fake name or email in Git?
Technically yes — Git does not verify that the name or email is real. But if you are working with other people, using a fake name makes it hard for them to know who wrote each piece of code. If you are pushing to GitHub or another service, using a real email helps that service connect your commits to your account.
What if I have multiple computers?
You need to set your username and email on each computer separately. Git stores these settings locally on the machine where you run the commands. If you get a new computer or use a different one, run the setup commands again on that machine.
How do I see all my Git settings at once?
Type git config --global --list to see all your global settings. This will show your username, email, and any other configuration you have set. If you want to see settings for just one project, navigate into that project's folder and type git config --list without the --global flag.