The two ways to change your Git username

Git stores your username in one of two places: on your computer only (local), or everywhere you use Git (global). Most people want global, which means one command changes your name for every project you work on. Local is useful if you work on a shared computer or need different names for different projects.

Both changes happen in terminal with a single line. You do not need to reinstall Git, restart your computer, or touch any files by hand. The change takes effect when ready on your next commit.

Key Takeaways

  • Global username change affects all your Git projects on this computer and requires the --global flag in your command.
  • Local username change affects only the current project folder and is useful if you need different names for work and personal repositories.
  • The command syntax is git config --global user.name "Your Name" for global or git config user.name "Your Name" for local.
  • You can verify the change worked by running git config --global user.name (global) or git config user.name (local) and seeing your new name print back.
  • Changing your username does not affect commits you already made — those keep the old name attached to them.

Setting a global username that applies everywhere

Open terminal on Mac or Linux, or PowerShell or Command Prompt on Windows. Type this command exactly, replacing "Your Name" with the name you want:

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

Press Enter. Terminal will not print anything back — that is normal. The command ran silently. Your new username is now set for every Git project on this computer.

If you also want to change your email address globally, use this command right after:

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

Setting a local username for just one project

Navigate to the project folder in terminal first. Use cd to move into the folder where your Git repository lives. For example: cd ~/Documents/my-project

Once you are inside the project folder, type this command:

git config user.name "Your Name"

Notice there is no --global flag this time. That tells Git to store this username only in this one project. Every other project on your computer keeps using your global username (or whatever local name you set for it separately).

Local settings override global settings, so if you set a global name and then set a different local name in a project folder, Git uses the local one for commits in that folder only.

Checking what username Git will use

To see what global username is currently set, type:

git config --global user.name

Terminal will print your current global username. If nothing prints, no global username is set yet.

To check the local username in a specific project, navigate into that project folder and type:

git config user.name

This shows the local username for that project only. If nothing prints, the project has no local override, so Git will use your global username instead.

Why your old commits still show the old name

Changing your username in Git does not change the name attached to commits you already made. Each commit records the username and email that were set at the moment you ran git commit. That information is permanent in the commit history.

If you need to change the name on old commits, that requires rewriting Git history, which is complex and affects anyone else working on the same repository. For most people, the right move is to leave old commits alone and start fresh with the new name going forward.

Common mistakes and how to avoid them

The most common mistake is forgetting the quotes around your name. If your name has spaces — like "Jane Smith" — you must wrap it in quotes. Without quotes, Git only captures the first word.

Another mistake is using --global when you meant local, or vice versa. Remember: --global means everywhere on this computer. No flag means just this project folder. If you set the wrong scope, just run the command again with the correct flag and it overwrites the previous setting.

On Windows, PowerShell and Command Prompt handle quotes slightly differently. If your command does not work in PowerShell, try Command Prompt instead, or use single quotes: git config --global user.name 'Your Name'

Frequently Asked Questions

Do I need to set both username and email?

No. Git requires only a username to make commits. Email is optional but recommended — most platforms like GitHub use it to link commits to your account. If you do not set email, Git uses a default based on your computer's username.

What if I use GitHub or GitLab — does changing my Git username change my account name?

No. Your Git username is local to your computer. Your GitHub or GitLab account name is separate and does not change. You can set your Git username to anything; it does not have to match your GitHub username. However, using the same name makes it easier to track who made which commits.

Can I have different usernames for different projects?

Yes. Set a global username first, then navigate into any project folder and use git config user.name "Different Name" (without --global) to override it for just that project. Git uses the local name for commits in that folder.

What if I typed the command wrong and want to undo it?

Just run the command again with the correct name. The new command overwrites the old setting. There is no undo needed — Git straightforward replaces the old value with the new one.

Does changing my username affect repositories I have already pushed to GitHub?

No. Commits you already pushed keep the old username attached. Changing your local Git username only affects new commits you make from now on. Old commits in the history remain unchanged.