How to add your username and email to Git
Git stores your username and email in a configuration file so that every commit you make is tagged with your identity. You set this once on your computer, and Git uses it automatically from then on. The process takes about two minutes and requires only a text editor or command line — no special software.
You have two choices: store your username and email for just one project folder, or store them for your entire computer. Most people choose the computer-wide option so they do not have to repeat the setup for each new project. Both methods use the same steps, with one small difference in the command you run.
Key Takeaways
- Git requires your username and email in its configuration file before you can commit code; this identifies who made each change.
- The fastest method is to open your terminal or command prompt and run two commands: one to set your username and one to set your email.
- Use the --global flag to save your settings for your entire computer, or leave it out to save settings for only the current project folder.
- You can verify your settings were saved by running git config --list and checking that your username and email appear in the output.
- If you need to change your settings later, run the same commands again with your new username or email.
Using the command line to set your username and email
Open your terminal (on Mac or Linux) or Command Prompt or PowerShell (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. Then type the second command, replacing your.email@example.com with your actual email address:
git config --global user.email "your.email@example.com"
Press Enter again. Git will not print a success message — silence means it worked. The --global flag tells Git to save these settings for every project on your computer. If you want to set username and email for only the current project folder, run both commands again without the --global flag.
Verifying your settings were saved
To confirm Git stored your username and email, type this command in your terminal:
git config --list
Press Enter. Git will print a long list of settings. Look for lines that say user.name=Your Name and user.email=your.email@example.com. If you see both lines with your information, the setup is complete.
If you used --global and want to see only your global settings, type git config --global --list instead. This filters out project-specific settings and makes the output shorter.
Editing the configuration file directly
If you prefer not to use the command line, you can edit Git's configuration file with a text editor. On Mac and Linux, the file is located at ~/.gitconfig in your home directory. On Windows, it is usually at C:\Users\YourUsername\.gitconfig.
Open the file with any text editor (Notepad, TextEdit, VS Code, or similar). Add or edit these lines:
[user] name = Your Name email = your.email@example.com
Save the file. Git will read these settings the next time you run a command. This method works the same way as the command line approach — you are just editing the file by hand instead of letting Git write it for you.
Setting different usernames for different projects
You might want to use one email for work projects and a different email for personal projects. After you set your global username and email, navigate to the project folder where you want different settings. Open your terminal in that folder and run the same commands without the --global flag:
git config user.name "Work Name" git config user.email "work.email@company.com"
Git will now use these settings only for that project folder. When you commit code in that folder, your work email will appear. When you commit in other folders, Git will use your global settings instead. You can set project-specific settings for as many folders as you need.
What happens if you commit without setting username and email
If you try to make your first commit without configuring Git, it will stop and show an error message telling you to set user.name and user.email. The error message usually includes the exact commands to run. You cannot commit until you provide this information — Git requires it for every single change you save.
Some systems have default fallback values (like your computer's username or a generic email), but relying on these is a bad idea. Your commits will be tagged with incorrect information, and other people working on the project will not know who made each change. Setting your real username and email takes two minutes and prevents confusion later.
Changing your username or email later
Run the same commands again with your new information. Git will overwrite the old settings:
git config --global user.name "New Name" git config --global user.email "newemail@example.com"
This only affects commits you make from this point forward. Any commits you already made will still show your old username and email — Git does not rewrite history. If you need to change the author information on past commits, that is a more advanced task that requires different tools.
Frequently Asked Questions
Can I use a fake name or email in Git?
Technically yes — Git stores whatever you type. But if you are working with other people or pushing code to a shared repository, using your real name and email makes collaboration easier. Others can contact you about your changes, and your work is properly credited to you.
Do I need to use the same email as my GitHub or GitLab account?
Not required, but it is recommended. If your Git email matches your GitHub email, GitHub will automatically link your commits to your account and show them on your profile. If they do not match, your commits will appear as "unverified" or unlinked to your account.
What if I get an error saying "git command not found"?
Git is not installed on your computer. You need to read and install Git first from git-scm.com before you can run any Git commands. After installation, restart your terminal and try the commands again.
Can I set username and email without using the command line?
Yes. You can edit the .gitconfig file directly with a text editor as described in the "Editing the configuration file directly" section. The result is identical — Git reads the same file either way.
What if I have multiple computers?
You need to set your username and email on each computer separately. Git stores settings locally on the machine where you run the commands. If you switch to a different computer, you will need to run the setup again there.