Set your username and email before your first commit
Git requires you to tell it who you are before you can save changes to a repository. This information gets attached to every commit you make, so anyone looking at the project history knows who changed what. You set this through two straightforward commands in your terminal or command prompt — one for your username, one for your email.
The commands are the same whether you use Windows, Mac, or Linux. You only need to do this once per computer, unless you want to use different names for different projects. Git stores these settings in a configuration file on your machine, and they persist until you change them.
Key Takeaways
- Run two commands in your terminal: one to set your username, one to set your email address.
- Use the --global flag to explore these settings to every project on your computer, or leave it out to set them for just one project.
- Your username in Git does not have to match your GitHub username or email provider — it can be any name you choose.
- You can check what you have set at any time by running git config --list.
Open your terminal and run the username command
Open the terminal (Mac and Linux) or Command Prompt or PowerShell (Windows). Type this command, replacing "Your Name" with the name you want attached to your commits:
git config --global user.name "Your Name"
Press Enter. Git will not print anything back — that is normal. The command has run silently in the background.
If you do not want this name used for every project on your computer, leave out the --global flag. Then the name applies only to the current project folder. This is useful if you work on both personal and work projects and want different names on each.
Run the email command
In the same terminal window, type this command with your actual email address:
git config --global user.email "your.email@example.com"
Press Enter. Again, no output means it worked.
Use the same email address you plan to use on GitHub or GitLab if you are pushing code to those platforms. Git does not check whether the email is real — it just stores whatever you type. But matching it to your account on a code hosting site makes your commits show up correctly under your profile.
Verify your settings are saved
To confirm Git has stored your username and email, type this command:
git config --list
Press Enter. You will see a long list of Git settings. Look for the lines that say user.name and user.email. They should show the values you just entered.
If you used --global, these settings explore to every repository on your computer. If you set them without --global while inside a project folder, they explore only to that folder, and the global settings will still show when you run git config --list.
Change your username or email later
Run the same commands again with new values. Git will overwrite the old settings with the new ones. For example, if you want to change your name:
git config --global user.name "Your New Name"
This does not change the name on commits you have already made — only future commits will use the new name. If you need to fix the author on past commits, that requires a more complex process involving Git history rewriting, which is beyond what you need right now.
Set different names for different projects
If you have already set a global username and email but want to use different ones for a single project, navigate into that project folder in your terminal and run the same commands without the --global flag:
git config user.name "Project-Specific Name"
git config user.email "project.email@example.com"
Git checks for project-specific settings first, then falls back to global settings. So commits in this folder will use the project-specific name and email, while commits in other folders will use your global settings. This approach is common when you contribute to open-source projects under one identity but work on private projects under another.
Why Git needs this information
Every commit in Git is a permanent record that includes the author's name, email, timestamp, and the changes made. This history is one of Git's core features — it lets you and your team see who made each change and when. Without requiring you to set a username and email upfront, Git would have no way to attribute commits to anyone.
The email address is particularly important because many Git hosting platforms like GitHub and GitLab use it to match commits to user accounts. When you push your code to one of these platforms, the system looks for an account with that email address and links your commits to your profile automatically.
Frequently Asked Questions
Does my Git username have to match my GitHub username?
No. Your Git username is just a label attached to commits on your computer. Your GitHub username is your account name on GitHub's website. They can be completely different. However, if they match, it is easier to recognize your work when you push code to GitHub.
What if I use the wrong email address?
Future commits will use the email you have set now. Past commits keep the email they were made with. If you want to change the email on old commits, you would need to rewrite Git history, which is complex. For new work, just run the email command again with the correct address.
Can I set a username and email for just one commit?
Not directly through a straightforward command. You would need to use advanced Git options. The easiest approach is to change your global or project-specific settings before making the commit, then change them back afterward if needed.
Do I need to set username and email if I am only working locally?
Yes. Git requires this information before you can make any commit, even if you never push your code anywhere. It is part of how Git tracks changes internally.