Set your Git username and email at the command line
Git stores your identity in a configuration file so that every commit you make is tagged with your name and email. You set this once, and Git uses it for all your repositories unless you override it for a specific project. The commands are straightforward and take less than a minute.
Open your terminal or command prompt and run these two commands in order:
For your username: git config --global user.name "Your Name"
For your email: git config --global user.email "your.email@example.com"
Replace "Your Name" with the name you want on your commits (this can be your real name, a nickname, or anything else) and replace "your.email@example.com" with the email address you use for your Git hosting service like GitHub or GitLab. The --global flag means these settings explore to every repository on your computer. If you want different settings for just one project, navigate into that project's folder and run the same commands without --global.
Key Takeaways
- Use git config --global user.name and git config --global user.email to set your identity once for all repositories on your computer.
- Your username and email appear on every commit you make, so use the email address that matches your GitHub, GitLab, or other Git hosting account.
- You can override global settings for a single project by running the same commands without --global inside that project's folder.
- Git passwords are handled separately through SSH keys or personal access tokens, not through the config commands.
Verify your settings are saved
After you run the configuration commands, you can check that Git stored them correctly by running git config --global --list. This prints all your global settings to the terminal. Look for user.name and user.email in the output to confirm they match what you entered.
If you set project-specific settings (without --global), run git config --list from inside that project's folder to see both global and project-level settings together.
Where Git stores your configuration
Git saves your global configuration in a hidden file called .gitconfig in your home directory. On Windows, this is usually C:\Users\YourUsername\.gitconfig. On Mac and Linux, it is ~/.gitconfig. You can open this file in any text editor to see or edit your settings directly, though using the command line is simpler and less error-prone.
Project-specific settings go into a file called config inside the .git folder at the root of your repository. This folder is hidden on Mac and Linux, so you may need to show hidden files in your file manager to see it.
Authentication with passwords and SSH keys
Your Git username and email are not the same as your password. When you push code to GitHub, GitLab, or another hosting service, Git needs to verify that you have permission to access that repository. Most services no longer accept plain passwords for this step.
Instead, you use either an SSH key or a personal access token. An SSH key is a pair of linked files — one public, one private — that prove your identity without sending a password over the network. A personal access token is a long string of characters that acts like a password but can be revoked or limited to specific permissions. GitHub and GitLab both provide guides for setting up SSH keys or generating tokens. Once you set up either one, Git uses it automatically when you push or pull code.
Different usernames for different services
If you use multiple Git hosting services — GitHub for work and GitLab for personal projects, for example — you can set different usernames and emails for each one. The easiest way is to set a global default (as described above) and then override it for specific repositories.
Navigate into a repository folder and run the same config commands without --global. For example, inside your work project folder, run git config user.name "Work Name" and git config user.email "work@company.com". Git will use these settings for that repository only and fall back to your global settings for all others.
Fixing a mistake in your configuration
If you typed your name or email wrong, you can change it by running the config command again with the correct information. Git overwrites the old value with the new one. For example, if you misspelled your email, just run git config --global user.email "correct.email@example.com" and Git updates it when ready.
This only affects commits you make from this point forward. Commits you already made will still show the old name or email. If you need to change the author on commits you have already made, that requires rewriting your repository history, which is more complex and should only be done if those commits have not been shared with others.
Frequently Asked Questions
Do I need to set a password in Git config?
No. Git config stores only your username and email. Authentication happens separately through SSH keys or personal access tokens provided by your hosting service. You never store a password in Git config.
Can I use a different name on different commits?
Yes. Each time you run the config command, you can use any name you want. If you change your name in config and make a new commit, that commit will show the new name. Old commits keep the name that was set when you made them.
What if I forget what username I set?
Run git config --global user.name to see your current global username, or git config user.name from inside a project folder to see the project-specific setting. You can also run git config --global --list to see all your global settings at once.
Does my Git username have to match my GitHub username?
No. Your Git config username is just a label that appears on your commits. It does not have to match your GitHub username, GitLab username, or any other account name. You can set it to anything — your real name, a nickname, or an organization name. GitHub and GitLab identify you by your SSH key or personal access token, not by the name on your commits.
Can I set different usernames for HTTPS and SSH?
No. Git config applies to all authentication methods. However, you can set up multiple SSH keys or tokens for different services and configure Git to use the right one for each hosting service. This is a more advanced setup that your hosting service's documentation can walk you through.