Set your Git identity before your first commit
Git requires a username and email address attached to every commit you make. These details appear in the commit history and help other people (or your future self) know who made each change. You set this information once on your computer, and Git uses it automatically for all your projects unless you override it for a specific folder.
The fastest way is to open your terminal or command prompt and run two commands. On Mac or Linux, open Terminal. On Windows, open Command Prompt or PowerShell. Then type the commands exactly as shown below, replacing the name and email with your own.
Key Takeaways
- Run git config --global user.name "Your Name" and git config --global user.email "your.email@example.com" to set your identity for all projects on your computer.
- The email you use in Git does not have to match your GitHub, GitLab, or other platform account, but using the same one makes it easier to track your work.
- Use the --global flag to set your identity once for your entire computer, or omit it to set identity for only the current project folder.
- Verify your settings worked by running git config --global user.name and git config --global user.email to see what Git has stored.
The two commands you need to run
Open your terminal and type this first command, replacing "Your Name" with your actual name:
git config --global user.name "Your Name"
Then type this second command, replacing the email with your actual email address:
git config --global user.email "your.email@example.com"
Press Enter after each command. Git will not print a success message — that is normal. If you see an error, check that you typed the command exactly, including the quotation marks and spaces.
The --global flag tells Git to remember these details for every project you work on from this computer. If you want to use different credentials for just one project, you can run the same commands again from inside that project folder, but without the --global flag.
Check that your settings were saved
To confirm Git stored your information correctly, run these two commands:
git config --global user.name
git config --global user.email
Git will print back the name and email you just set. If you see the correct information, you are done. If you see nothing or the wrong information, run the original two commands again and check for typos.
Why the email matters for platforms like GitHub
When you push your commits to GitHub, GitLab, or another platform, Git sends the email address you configured. If that email matches an account on the platform, the platform will link your commits to your profile automatically. If the email does not match, your commits will still upload, but they may show as coming from an unknown user.
You do not have to use your real email address in Git. Many people use a fake or masked email for privacy. The only requirement is that if you want your commits linked to your GitHub profile, the email in Git must match the email in your GitHub account settings.
Setting different credentials for one project
If you work on projects for different clients or organizations, you might want to use different names or emails for different folders. To do this, navigate into the project folder in your terminal, then run the same two commands without the --global flag:
git config user.name "Client Name"
git config user.email "client.email@example.com"
Git will now use these credentials only for commits in that folder. All other projects will continue using your global settings. This is useful if you contribute to open-source projects under one name and work on client projects under another.
Fixing a mistake in an old commit
If you made commits with the wrong name or email before you changed your settings, those old commits keep the incorrect information. Changing your Git config now will not fix commits you already made. For a single recent commit that has not been pushed yet, you can run git commit --amend --author="Correct Name <correct.email@example.com>" to rewrite it.
For multiple old commits or commits you have already pushed to a shared repository, the process is more complex and can cause problems if other people have already pulled your code. In most cases, it is better to leave old commits as they are and use the correct credentials going forward.
Frequently Asked Questions
Does my Git email have to be the same as my GitHub email?
No, but if you want GitHub to link your commits to your profile, they must match. You can use any email in Git. If it does not match your GitHub account email, your commits will still upload, but they will show as coming from an unknown contributor instead of your profile.
Can I use a fake name or email in Git?
Yes. Git does not verify that the name or email is real. Many people use pseudonyms or masked emails for privacy. The only limit is if you are working on a team or open-source project with rules about how commits must be attributed.
What if I forget to set my Git config and make a commit?
Git will refuse to create the commit and ask you to set your name and email first. You cannot make any commits until you run the two config commands. This is a safety feature to prevent commits with missing information.
How do I change my Git username and email after I set them?
Run the same two commands again with the new name and email. Git will overwrite the old settings. All future commits will use the new information, but old commits will keep their original author details.