Set your Git username and email from the command line
Git stores your name and email address in a configuration file so that every commit you make is tagged with your identity. You set these values once using the git config command, and Git remembers them for future commits. The command is the same whether you use Windows, Mac, or Linux — you type it into your terminal or command prompt.
The fastest way is to set them globally, which means they explore to every repository on your computer. Open your terminal or command prompt and type these two commands, replacing the name and email with your own:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
After you run each command, Git saves the setting and returns you to the prompt with no message — that silence means it worked. You do not need to restart anything or open Git again; the change takes effect when ready.
Key Takeaways
- Use git config --global user.name and git config --global user.email to set your identity for all repositories on your computer.
- The global setting saves to a file on your computer and persists until you change it again.
- You can set different names and emails for individual repositories by running the same commands without the --global flag inside that repository's folder.
- Verify your settings at any time by typing git config --global user.name or git config --global user.email to see what Git has stored.
Verify what Git has stored
After you set your username and email, you can check that Git saved them correctly. Type this command to see your name:
git config --global user.name
Git will print back exactly what you entered. Do the same for email:
git config --global user.email
If you see the values you just set, the configuration is complete. If you see nothing or an error, the command did not run correctly the first time — try typing it again, making sure you include the quotes around your name and email.
Set different username and email for one repository only
Sometimes you need a different name or email for a specific project — for example, if you use your work email for one repository and your personal email for another. You can override the global setting for just that repository.
Navigate into the repository folder using your terminal or command prompt, then run the same commands without the --global flag:
git config user.name "Your Work Name"
git config user.email "work.email@company.com"
Now any commit you make inside this folder will use the work name and email, while commits in other repositories will use your global settings. The repository-level setting overrides the global one only for that folder.
Find where Git stores your configuration
Git saves your global configuration in a hidden file on your computer. On Mac and Linux, it is located at ~/.gitconfig. On Windows, it is usually at C:\Users\YourUsername\.gitconfig. You can open this file in any text editor to see all your Git settings in one place.
Repository-level settings are stored in a file called config inside the .git folder at the root of your repository. You rarely need to edit these files directly — using the git config command is simpler and less error-prone.
Change your username or email later
If you need to update your name or email, straightforward run the git config command again with the new value. Git will overwrite the old setting with the new one:
git config --global user.name "Your New Name"
This does not change the name or email on commits you have already made — those are permanent once committed. Only future commits will use the new name and email. If you need to change the author on past commits, that requires a more complex process called rebasing, which is beyond the scope of basic configuration.
Troubleshoot common configuration problems
If Git is not using the name or email you set, the most common cause is a typo in the command itself. Check that you included the quotes around your name and email, and that you spelled user.name and user.email correctly — Git will not warn you if the command is slightly wrong.
Another common issue is forgetting the --global flag when you meant to set a global value. If you run the command inside a repository folder without --global, it sets only that repository's configuration, and your global setting remains unchanged. To fix this, run the command again with --global added.
If you have set both a global and a repository-level configuration, Git always uses the repository-level one for commits in that folder. This is intentional — it lets you override your global settings for specific projects.
Frequently Asked Questions
Does my username have to be my real name?
No. Git stores whatever text you provide in the user.name field. Many developers use a nickname, a handle, or a shortened version of their name. The only requirement is that you use the same name consistently if you want your commits grouped together in a repository's history.
What email should I use if I do not want my address public?
If your repository is public on a platform like GitHub, your email will be visible to anyone who views the commit history. Many platforms offer a private or noreply email address you can use instead. Check your account settings on the platform where you host your code for the option to use a masked email.
Can I set my username and email through a graphical interface instead of the command line?
Some Git graphical tools and code editors have settings panels where you can enter your name and email, and they run the git config command behind the scenes. However, using the command line directly is faster and works the same way on every computer, so it is the most reliable method.
What happens if I do not set a username and email before making a commit?
Git will refuse to create a commit and will show an error message telling you to set user.name and user.email. You must configure these values before you can commit anything. This is by design — Git requires every commit to have an author.
Do I need to set my username and email on every computer I use?
Yes. Each computer has its own copy of the Git configuration file. If you clone a repository on a new machine and have not set your global configuration yet, you will need to run the git config commands again on that machine before you can commit.