Why Git needs your username and email

Git records who made each change to your code. When you commit — save a version of your work — Git stamps it with a name and email address. This isn't for logging into anything. It's metadata that appears in your project history so your team knows who wrote what, and so you can find your own changes months later.

If you don't set these, Git will either use defaults from your system or refuse to let you commit at all. Setting them once takes two minutes and works across every project on your computer.

Key Takeaways

  • Git stores your username and email with every commit you make, so teammates can see who changed what.
  • The git config command sets these values, and you can configure them globally (for all projects) or per project.
  • Global configuration lives in a hidden file in your home directory and applies to every repository unless you override it.
  • You can use any name and any email address — Git does not verify them against a real account.

Setting username and email globally

Global configuration applies to every Git project on your computer. Open your terminal or command prompt and run 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"

Git stores these in a hidden file called .gitconfig in your home directory. You can verify they were set by running git config --global --list, which shows all your global settings. The name and email you enter can be anything — Git does not check them against a real account or send mail to that address.

After you run these commands, every commit you make on your computer will use this name and email unless you override them in a specific project. This is the most common setup for developers who work on personal projects or use the same identity across all their work.

Setting username and email for one project only

If you want different credentials for a specific project — for example, using your work email for a work repository and your personal email for a hobby project — you can override the global setting in that project alone.

Navigate into the project folder in your terminal, then run the same commands without the --global flag:

git config user.name "Your Name"

git config user.email "your.email@example.com"

This creates a local configuration file inside the project's .git folder. When you commit in this project, Git uses the local settings. In all other projects, it falls back to your global settings. Local settings always take priority, so if you have both global and local configuration, Git will use the local one for that specific project.

Checking what you have configured

To see your global settings, run git config --global --list. To see what Git will actually use in your current project (combining global and local settings), run git config --list.

Look for the lines starting with user.name and user.email. If you set local overrides in the current project, those will appear in the list and take priority over the global ones. This is useful when you want to confirm which identity Git will use before you make your next commit.

What happens if you do not set these

On some systems, Git will use your computer's username and a default email. On others, Git will refuse to commit and show an error message telling you to set user.name and user.email. Either way, the solution is the same: run the two config commands above.

If you have already made commits without setting these, the commits are already stamped with whatever Git used. You can change your configuration going forward, but the old commits will keep their original author information. This is why it's useful to set these values early, before you start making commits in a new project.

Changing your username or email later

Run the same git config commands again with new values. They overwrite the old ones. For example, if you change jobs and want to use a new email address, run git config --global user.email "newemail@example.com".

This affects only commits you make from that point forward. Commits you have already made keep their original author information. If you need to change the author on old commits, that requires a more complex process involving Git history rewriting, which is beyond the scope of basic setup.

Frequently Asked Questions

Can I use a fake name or email address?

Yes. Git does not verify either value against a real account or send anything to the email address. The name and email are just text that appears in your commit history. Many developers use their real name and email, but Git does not require it.

Do I need to set these differently for GitHub, GitLab, or other services?

No. Your Git username and email are separate from your account on GitHub or any other service. Git uses them only to stamp your commits. You log into GitHub with your GitHub username and password, which is different.

What if I work on multiple projects with different teams?

Set your global username and email to what you use most often, then use local configuration to override them in specific projects. Navigate into each project folder and run the config commands without --global.

Can I see who made each commit after I set this up?

Yes. Run git log to see a list of commits with the author name and email for each one. You can also see this on GitHub, GitLab, or other services when you view your repository history.