Change your Git username and email from the command line

Git stores your username and email in a configuration file on your computer. To change them, you open a terminal or command prompt and run two commands that overwrite the old values with new ones. The change takes effect when ready for all new commits you make.

The simplest approach is to set these values globally, which means they explore to every repository on your machine. If you need different credentials for a specific project — say, your work email for one folder and your personal email for another — you can set them locally within just that folder instead.

Before you start, decide whether you want to change your settings for all repositories or just one. Most people change them globally the first time, then override them locally only when needed.

Key Takeaways

  • Run git config --global user.name "Your Name" and git config --global user.email "your.email@example.com" to change your username and email for all repositories on your computer.
  • Remove the --global flag and run the same commands inside a specific folder to change settings for only that project.
  • Use git config user.name and git config user.email (without a value) to check what your current settings are before making changes.
  • Changes to Git configuration do not affect commits you have already made — only new commits going forward will use the new username and email.
  • If you are on Windows, use Command Prompt or PowerShell; on Mac or Linux, use Terminal.

Set your username and email globally

Open your terminal or command prompt. On Windows, search for "Command Prompt" or "PowerShell" in the Start menu. On Mac, open Applications > Utilities > Terminal. On Linux, open your terminal process.

Type the first command exactly as shown, replacing "Your Name" with your actual name:

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

Press Enter. You will not see any confirmation message — that is normal. Git only prints output if something goes wrong.

Now type the second command, replacing "your.email@example.com" with your actual email address:

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

Press Enter again. Both settings are now saved. Any new commits you make from this point forward will use the new name and email.

Set your username and email for one project only

If you need different credentials for a specific repository — for example, your work email for a company project and your personal email for a hobby project — you can override the global settings for just that folder.

Open your terminal and navigate to the project folder. On Windows, you can type cd C:\Users\YourUsername\path\to\project. On Mac or Linux, type cd ~/path/to/project. Replace the path with the actual location of your project folder.

Once you are inside the project folder, run the same two commands but without the --global flag:

git config user.name "Your Work Name"
git config user.email "work.email@company.com"

These settings now explore only to this repository. When you commit changes here, Git will use these credentials. In all other repositories on your machine, Git will still use your global settings.

Check what your current settings are

Before you change anything, you may want to see what username and email Git is currently using. Type this command to check your global username:

git config --global user.name

Git will print your current global username. To check your global email, type:

git config --global user.email

If you are inside a project folder and want to check the local settings for just that repository, run the same commands without the --global flag. If a local setting exists, Git will show it. If not, Git will show nothing, which means that repository is using your global settings.

Understand where Git stores these settings

Git saves your global configuration in a hidden file on your computer. On Mac and Linux, this file is located at ~/.gitconfig in your home directory. On Windows, it is usually at C:\Users\YourUsername\.gitconfig.

You can open this file in any text editor to see all your Git settings at once, or to make changes manually. However, using the command line is faster and less error-prone for most people.

Local settings for a specific repository are stored in a hidden folder called .git inside that project. You rarely need to edit these files directly — the command line approach is the standard way to change them.

What happens to commits you already made

Changing your Git username and email does not affect commits you have already made. Those commits keep the old name and email permanently. Only new commits going forward will use the new credentials.

If you need to change the author information on commits you have already made, that requires a more complex process called rebasing or amending history. For most situations, you straightforward make the change and move forward with the new settings.

Troubleshooting common problems

If you type a command and see an error like "git is not recognized", Git is not installed on your computer or your system cannot find it. You will need to install Git first before you can change these settings. Visit git-scm.com and read the installer for your operating system.

If you see a message like "fatal: not a git repository", you are trying to set local settings outside of a Git project folder. Make sure you have navigated into the correct project directory before running the command without the --global flag.

If you are not sure whether your changes took effect, use the check commands from the earlier section to verify. Type git config --global user.name and confirm that Git prints back the name you just set.

Frequently Asked Questions

Do I need to change my Git username and email if I already have a GitHub account?

No. Your Git configuration on your computer is separate from your GitHub account. You can have any username and email in Git, and they do not have to match your GitHub username or email. However, if you want your commits to show up as yours on GitHub, the email in your Git config should match an email address you have registered on GitHub.

Can I use a fake name or email in my Git config?

Yes. Git will accept any text you put in these fields. However, if you are pushing commits to a shared repository like GitHub, using a real name and email makes it clear who made each change. For personal projects, you can use whatever you want.

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

Change your Git config to the correct email now, and all future commits will use the new email. The old commits keep the wrong email, but you can correct them later if needed using Git's rebase or amend features. For most situations, straightforward fixing it going forward is the easiest approach.

Do I have to use the command line, or can I change these settings another way?

The command line is the standard method and works the same way on all operating systems. Some Git graphical interfaces and code editors like Visual Studio Code have built-in settings panels where you can change these values, but the command line approach is the most reliable and fastest.

Will changing my Git config affect my existing local files?

No. Changing your username and email only affects new commits you create. Your actual project files are not touched. The change only applies to the metadata Git stores about who made each commit.