Change your Git username and email with command line or configuration files
Git stores your username and email in a configuration file so it can attach your name to every commit you make. If you set up Git with the wrong name or email, or you need to change it later, you can update both settings in a few minutes using either the command line or by editing the configuration file directly. The change takes effect when ready on your next commit.
Your Git username is separate from your GitHub username, GitLab username, or any other service you use. Git only cares about the name and email stored in its local configuration. You can have a different username in Git than you do on the platform where you host your code.
Key Takeaways
- Use git config user.name "Your Name" and git config user.email "your@email.com" to change settings for a single repository.
- Add the --global flag to change your username and email for all repositories on your computer.
- Check your current settings with git config user.name and git config user.email before making changes.
- Changes only affect new commits — past commits keep the old username and email attached to them.
- If you use multiple repositories with different identities, set the username and email per repository instead of globally.
Check what username and email Git currently has
Before you change anything, see what Git is currently set to. Open your terminal or command prompt and type git config user.name. Git will print the name it has stored. Then type git config user.email to see the email.
If you get no output, Git does not have a username or email set yet. If you get an error like "fatal: not a git repository", you are not inside a Git repository folder. Navigate to a folder that contains a Git project and try again.
Change username and email for one repository only
If you want the new username and email to explore only to the current project, navigate into that project's folder in your terminal. Then type git config user.name "Your New Name", replacing "Your New Name" with the name you want. Press Enter.
Next, type git config user.email "your.new@email.com", replacing the email with your actual email address. Press Enter. Verify the changes took effect by running git config user.name and git config user.email again — Git should print back what you just entered.
These changes are stored in a file called .git/config inside your project folder. They only affect commits you make in this specific repository. Other repositories on your computer keep their own settings.
Change username and email for all repositories on your computer
If you want Git to use the same username and email for every repository you work on, use the --global flag. Type git config --global user.name "Your New Name" and press Enter. Then type git config --global user.email "your.new@email.com" and press Enter.
Global settings are stored in a file in your home directory. On Windows, this is usually C:\Users\YourUsername\.gitconfig. On Mac and Linux, it is ~/.gitconfig. You can open and edit this file directly if you prefer, but the command line method is faster and less error-prone.
If you later set a username and email for a specific repository without the --global flag, that repository's settings override the global ones. This is useful if you work on personal projects and work projects from the same computer.
Edit the configuration file directly
Instead of using commands, you can open the Git configuration file in a text editor and change the values yourself. For a single repository, open the file .git/config in the project folder. For global settings, open .gitconfig in your home directory.
Look for the section that starts with [user]. You should see two lines: name = Your Old Name and email = your.old@email.com. Change the values after the equals sign to your new name and email. Save the file. The next time you make a commit, Git will use the new values.
If the [user] section does not exist in the file, you can add it yourself. Type the section header [user] on its own line, then add name = Your Name and email = your@email.com on the lines below it. Save the file.
Understand what changes and what stays the same
Changing your Git username and email only affects commits you make from this point forward. Any commits you already made keep the old username and email attached to them. If you push those old commits to GitHub, GitLab, or another service, they will still show the old name and email in the history.
If you need to change the author information on past commits, you can use git commit --amend to rewrite the most recent commit, or git rebase to rewrite multiple commits. These are advanced operations that change the commit history, so use them only if you have not yet pushed the commits to a shared repository.
Frequently Asked Questions
Do I need to change my username on GitHub or GitLab too?
No. Your Git username is stored locally on your computer and is separate from your account username on any platform. You can change your Git username without touching your GitHub account. However, if you want commits to show up as yours on GitHub, the email in Git should match the email on your GitHub account.
What if I use different emails for different projects?
Set the username and email per repository instead of globally. Navigate into each project folder and run git config user.email "project@email.com" without the --global flag. Git will use that email only for commits in that folder, while other repositories use their own settings or the global default.
Can I see who made a commit after I change my username?
Yes. Type git log to see the commit history with the author name and email for each commit. The commits you made before the change still show the old name. Commits you make after the change show the new name. The git log command does not change — it just displays what is already stored in each commit.
What if I forget whether I set a global or repository-specific username?
Type git config user.name to see the current setting for the repository you are in. If you want to see the global setting, type git config --global user.name. If both are set, the repository-specific one takes priority for commits in that folder.