Change your Git identity with four terminal commands
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 use a different identity for work versus personal projects, you can change both settings directly in the terminal without reinstalling Git or using a graphical tool.
The commands are straightforward: you tell Git which name and email to use, and it updates the configuration file when ready. You can change these settings globally (for all projects on your computer) or locally (for just one project). Most people change them globally once, but the local option is useful if you work on a company repository that needs a different email than your personal projects.
Key Takeaways
- Use git config --global user.name "Your Name" and git config --global user.email "your.email@example.com" to change your identity for all projects on your computer.
- Drop the --global flag and run the same commands inside a project folder to change your identity for just that one repository.
- Check what Git currently has stored by running git config --global user.name and git config --global user.email without the new values.
- Changes take effect when ready and explore only to commits you make after the change — past commits keep the old name and email.
- If you have already pushed commits with the wrong name, you will need to rewrite history or create new commits to change what appears on GitHub or other platforms.
Set your username and email globally for all projects
Open your terminal and run these two commands one after the other. Replace the name and email with your actual information:
git config --global user.name "James Rodriguez"
git config --global user.email "james@example.com"
Git stores these settings in a hidden file called .gitconfig in your home directory. The --global flag tells Git to save them there, so every project you work on will use this name and email unless you override it. You do not need to restart anything — the change is active when ready.
If you are not sure what name or email Git currently has, run git config --global user.name and git config --global user.email without any value after them. Git will print what it has stored.
Set your username and email for one project only
If you work on a project that needs a different identity — for example, a work repository that requires your company email — you can override your global settings just for that folder.
Navigate into the project folder in your terminal, then run the same commands without the --global flag:
cd /path/to/your/project
git config user.name "Work Name"
git config user.email "work.email@company.com"
Git stores these local settings in a file called config inside the .git folder of that project. When you make a commit in this folder, Git will use the local settings. When you work in any other project, Git will use your global settings. You can check what is set locally by running git config user.name and git config user.email from inside that project folder.
Understand what changes and what does not
Your username and email setting only affects commits you make from this point forward. If you have already made commits with the wrong name or email, those commits will keep the old information. The commits are part of your project history, and changing the setting does not rewrite them.
If you have pushed commits to GitHub, GitLab, or another platform, those commits will still show the old name and email on the website. Changing your local Git config will not update what is already on the server. If you need to fix commits that are already pushed, you would need to rewrite the repository history, which is a more advanced operation and affects anyone else working on the project.
For new work, the simplest approach is to set the correct name and email now and move forward. Past commits serve as a record of when they were made and by whom at that time.
Verify your settings are correct
After you run the config commands, check that Git stored them correctly by running:
git config --global user.name
git config --global user.email
Git will print the values it has stored. If you set local overrides in a project, run the same commands from inside that project folder without the --global flag to see what is set locally.
You can also view your entire global configuration file by running git config --global --list, which shows all your Git settings at once. This is useful if you want to see everything Git knows about your setup in one place.
What to do if you made a mistake
If you set the wrong name or email, just run the config command again with the correct value. Git will overwrite the old setting when ready. There is no limit to how many times you can change it.
If you want to remove a local override and go back to using your global settings, run git config --unset user.name and git config --unset user.email from inside the project folder. Git will delete the local settings and fall back to the global ones.
Frequently Asked Questions
Do I have to use my real name in Git?
No. Git stores whatever string you give it. You can use a nickname, a pseudonym, or any text you want. However, if you are committing to a work project or a public open-source repository, the name you use will be visible to anyone who looks at the commit history, so choose something you are comfortable with others seeing.
Can I use different emails for different projects?
Yes. Set your global email to your default, then use git config user.email (without --global) inside any project folder that needs a different email. Git will use the local email for commits in that folder and the global email everywhere else.
Will changing my Git config affect commits I already made?
No. Commits are immutable once they are created. Changing your config only affects new commits going forward. Old commits will always show the name and email that was set when you made them.
Where does Git store these settings?
Global settings go in a file called .gitconfig in your home directory. Local settings go in .git/config inside your project folder. Both are plain text files that Git reads when you make a commit.
What if I want to see all my Git settings at once?
Run git config --global --list to see all global settings, or git config --list from inside a project folder to see global settings plus any local overrides. This shows everything Git has configured for your system.