Set your Git username with a single command

Your Git username is the name that appears on every commit you make. To set it, open your terminal or command prompt and run one of two commands depending on whether you want the username to explore everywhere you work or only in one folder.

For a username that applies to all your projects on this computer, run:

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

For a username that applies only to one specific project folder, navigate into that folder first, then run:

git config user.name "Your Name"

Replace "Your Name" with whatever name you want to appear on your commits. You do not need quotes if your name is one word, but quotes are safer and always work.

Key Takeaways

  • Use git config --global user.name "Your Name" to set a username that applies to every project on your computer.
  • Use git config user.name "Your Name" without the --global flag to set a username for only the current project folder.
  • The username you set here is what appears on your commits and is visible to anyone who sees your code history.
  • You can change your username at any time by running the same command with a different name — new commits will use the new name, but old commits keep their original username.

The difference between global and project-specific usernames

When you use the --global flag, Git stores your username in a configuration file on your computer that applies everywhere. This is the right choice if you work on multiple projects and want the same name on all of them. On Windows, this file lives in your user folder as .gitconfig. On Mac and Linux, it is in your home directory with the same name.

Without the --global flag, Git stores the username only in the current project folder, in a hidden .git/config file inside that project. This is useful if you work on projects for different clients or organizations and want different names on each one. A project-specific username overrides your global username, so if you set both, Git uses the project-specific one for that folder.

How to check what username you have set

To see what username Git is currently using, run:

git config user.name

This shows your global username if you have one. To check the username for only the current project folder, run:

git config --local user.name

If you have set both a global and a project-specific username, the project-specific one takes priority. Running the first command from inside a project folder shows whichever one Git will actually use.

What happens if you do not set a username

If you try to make a commit without setting a username, Git will refuse and show an error message telling you to run git config user.name. The error message on newer versions of Git is usually clear about what to do. On older versions, the message may be harder to understand, but the solution is the same: set your username using the command above.

Some hosting services like GitHub can infer a username from your account when you push code, but Git itself still requires a local username to be set before you commit. Setting it prevents errors and makes sure your commits are labeled correctly from the start.

Setting both username and email at the same time

Git also requires an email address alongside your username. You can set both in separate commands, or set them together by running both commands in sequence. The email command is:

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

Many people set both their username and email in the same session. The order does not matter. If you forget to set your email, Git will show a similar error message when you try to commit, and you can set it then.

Changing your username for existing commits

Changing your username with git config only affects new commits going forward. Commits you have already made keep their original username. If you need to change the username on commits that are already in your history, that requires a more complex process that rewrites your commit history, and is usually not necessary unless you are working alone on a private project.

For most situations, it is fine to change your username and let old commits show the old name. If you push commits to a shared repository like GitHub, changing history after pushing can cause problems for other people working on the same code, so avoid it unless you have a specific reason.

Frequently Asked Questions

Can I use a different username for different projects?

Yes. Set a global username with git config --global user.name, then navigate into any project folder where you want a different name and run git config user.name without the --global flag. That project will use its own username while all others use the global one.

Does my Git username have to match my GitHub username?

No. Your Git username is just a label on your commits and can be anything. Your GitHub username is separate and is what appears in your GitHub profile URL. You can set your Git username to your real name, a nickname, or anything else, regardless of what your GitHub account is named.

What if I set the wrong username?

Run the same command again with the correct name. Git will overwrite the old setting when ready. Any new commits will use the new username, but old commits keep their original username. There is no penalty for changing it.

Do I need to set a username on every computer I use?

Yes. The --global flag only stores the username on the computer where you run the command. If you work on another computer or reinstall your operating system, you need to set your username again on that machine.

Can I set a username without opening the terminal?

Not directly. Git configuration requires running commands in a terminal or command prompt. On Windows, you can use Command Prompt, PowerShell, or Git Bash. On Mac and Linux, use Terminal. There is no graphical interface built into Git itself, though some code editors have Git panels that may offer shortcuts.