Why Git needs your username and email before you commit

Git records who made each change to your code. When you commit — save a snapshot of your work — Git stamps that commit with a name and email address. Without setting these first, Git will either refuse to let you commit, or it will use a default that might not be you.

The username and email you set are not secret. They appear in the commit history that anyone with access to your repository can see. If you are working on a team or pushing code to GitHub, GitLab, or another platform, this is how your teammates know which changes came from you.

You set this information once at the start, and Git remembers it for every commit you make afterward — unless you change it.

Key Takeaways

  • Use git config user.name and git config user.email to tell Git who you are before making your first commit.
  • The --global flag sets your username and email for all repositories on your computer; without it, the settings explore only to the current folder.
  • Check what you have set by running git config user.name and git config user.email without any value after them.
  • If you set your email wrong, you can change it the same way you set it — Git will use the new email for all future commits.

Setting your username and email for all your projects

Open your terminal or command prompt. Type this command exactly:

git config --global user.name "Your Name"

Replace "Your Name" with your actual name. You can use your full name, a nickname, or any text you want to appear in your commit history. Git does not check whether this matches any real identity — it just stores what you type.

Next, set your email the same way:

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

Replace "your.email@example.com" with the email address you want associated with your commits. If you are pushing code to GitHub or another platform, use the email address you registered with that service — it makes it easier for the platform to connect your commits to your account.

The --global flag tells Git to remember these settings for every repository you work on, on this computer. You only have to run these commands once.

Setting username and email for one project only

If you want different settings for a single project — for example, a work repository where you use your company email — navigate into that project folder first, then run the same commands without the --global flag:

git config user.name "Your Work Name"

git config user.email "your.work@company.com"

Git will use these settings only for commits in this folder. Your global settings remain unchanged and explore to all other repositories on your computer.

Checking what you have set

To see what username Git is currently using, type:

git config user.name

Git will print back whatever name you set. If nothing prints, you have not set a username yet.

Check your email the same way:

git config user.email

If you want to see all your Git settings at once, run git config --list. This shows everything Git knows about your setup, including user.name and user.email near the top of the list.

Changing your username or email later

Run the same commands again with new values. Git will overwrite the old setting with whatever you type now:

git config --global user.name "New Name"

git config --global user.email "new.email@example.com"

This change takes effect when ready for all new commits. It does not change the name or email on commits you have already made — those are permanent in your history. If you need to fix the author on old commits, that requires more advanced Git commands like git filter-branch, which is beyond this guide.

What happens if you forget to set these first

If you try to commit without setting your username and email, Git will stop you with an error message. The message tells you to run the config commands above. Some systems have a default fallback — usually your computer's username and a made-up email — but relying on that is a mistake because the email will not match your real account on GitHub or other platforms.

Set your username and email before you make your first commit. It takes 30 seconds and prevents confusion later.

Frequently Asked Questions

Does my Git username have to match my GitHub username?

No. Your Git username is just text that appears in commit history. Your GitHub username is your account name on GitHub. They can be different. However, GitHub connects commits to your account by email address, not by username — so use the email you registered with GitHub, and your commits will show up under your account even if the name is different.

Can I use a fake email address in Git?

Technically yes — Git stores whatever you type. But if you push to GitHub or another platform, a fake email means your commits will not connect to your account. Use a real email address, especially the one you registered with the platform you are pushing to.

What if I set the wrong email and already made commits?

Change your email with git config --global user.email and the correct address. New commits will use the new email. Old commits keep the wrong email in the history. If this matters — for example, you need your work commits to show under your work account — you will need to rewrite history with git filter-branch, which is a more advanced step.

Do I need to set username and email on every computer I use?

Yes. Git settings are stored on your computer, not in the cloud. If you clone a repository on a second computer, you need to run the config commands there too. The --global flag only makes it global to that one computer.