Git needs your username and email before you can save your work
When you commit code to Git, it records who made the change and when. Git stores this information using a username and email address you configure on your computer. Without setting these first, Git will either refuse to commit or use a default that may not be yours. You configure this once per computer, and Git remembers it for every project you work on afterward.
The process takes two commands and about one minute. You can set these values globally (so they explore to every project on your machine) or locally (so they explore to just one project folder). Most people set them globally and change them only if they work on a project that needs different attribution.
Key Takeaways
- Run two commands in your terminal or command prompt to set your Git username and email globally on your computer.
- Use git config --global user.name "Your Name" and git config --global user.email "your.email@example.com" to configure Git for all projects.
- Omit the --global flag and run the commands inside a project folder to set username and email for that project only.
- Check what you have configured by running git config user.name and git config user.email without the assignment part.
Setting username and email globally for your entire computer
Open your terminal (on Mac or Linux) or command prompt (on Windows). Type the first command exactly as shown, replacing "Your Name" with your actual name:
git config --global user.name "Your Name"
Press Enter. Git will not print anything back — that is normal. Then type the second command, replacing the email address with your actual email:
git config --global user.email "your.email@example.com"
Press Enter again. Both commands are now complete. Every time you commit code on this computer, Git will use the name and email you just entered. You do not need to repeat these steps unless you want to change them later.
Setting username and email for one project only
If you work on a project that should use different attribution than your global settings, you can override them for just that folder. Open your terminal or command prompt and navigate into the project directory using cd path/to/your/project.
Then run the same two commands, but leave out the --global flag:
git config user.name "Different Name"
git config user.email "different.email@example.com"
Now commits in this folder only will use the local settings. When you work in other projects, Git will fall back to your global username and email. This is useful if you contribute to an open-source project under a pseudonym or if your work email differs from your personal one.
Checking what you have configured
To see what username and email Git is currently set to use, run these commands:
git config user.name
git config user.email
Git will print back whatever values you have set. If you want to see all your Git configuration settings at once, type git config --list. This is helpful if you have set local overrides in a project folder and want to confirm which settings are active.
Changing your username or email later
Run the same commands again with new values. Git will overwrite the old settings with the new ones. If you set them globally and want to change them globally, use the --global flag. If you want to change only the local settings for one project, navigate into that project folder and run the commands without the flag.
Changing your configuration does not affect commits you have already made — those keep the username and email that were set when you made them. Only new commits going forward will use the updated values.
Why Git requires this information
Git is a version control system that tracks who changed what and when. The username and email you configure become part of the permanent record of every commit you make. This matters when you push your code to a shared repository like GitHub or GitLab, because other people can see who made each change. It also matters if you ever need to audit your own work or revert a specific change — Git uses this information to identify which commits are yours.
The email does not have to be real or reachable. You can use any text in the email field. However, if you plan to push code to a shared repository, using a real email makes it easier for teammates to contact you about your changes.
Troubleshooting common problems
If Git tells you "fatal: not in a git repository" when you try to run a config command, you are in the wrong folder. Make sure you have navigated into your project directory using cd, or use the --global flag to configure Git for your entire computer instead.
If you see an error about quotes or special characters, make sure your name and email are wrapped in double quotes, like "Your Name" and "your.email@example.com". If your name contains a quote mark or apostrophe, escape it with a backslash: "O\'Brien".
If you have already made commits without configuring Git, those commits will have a default or blank username. You cannot change the author of past commits without rewriting history, which is complex and not recommended for shared repositories. Going forward, your new configuration will explore to all future commits.
Frequently Asked Questions
Do I have to use my real name?
No. Git stores whatever text you put in the user.name field. You can use a nickname, pseudonym, or any other identifier. However, if you work on shared projects, using a name your teammates recognize makes collaboration easier.
Can I use different usernames for different projects?
Yes. Set a global username and email for your computer, then navigate into any project folder and run the same commands without --global to override them locally. Git will use the local settings for that project and the global settings everywhere else.
What happens if I do not set username and email before my first commit?
Git will refuse to create a commit and will print an error message telling you to configure user.name and user.email. Some systems have a default fallback, but it is unreliable. Set these values before you try to commit.
Does the email have to match my GitHub or GitLab account?
It does not have to match, but GitHub and GitLab use the email to link commits to your account. If you use a different email in Git than you registered with, your commits may appear as coming from an unknown user. Check your platform's documentation for how to add multiple email addresses to your account.
Can I set username and email in a config file instead of using commands?
Yes. Git stores configuration in a plain text file. On Mac and Linux, the global config is at ~/.gitconfig. On Windows, it is usually at C:\Users\YourUsername\.gitconfig. You can edit this file directly with any text editor, but using the commands is simpler and less error-prone.