How to change my Git username in terminal?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Changing your Git username in the terminal usually means changing the user.name setting in Git config. The important distinction is scope: you can set it globally for all repositories on the machine or locally for one repository only. That setting affects future commits, not commits that already exist in history.
Check the Current Value First
Before changing anything, inspect the current config.
Global value:
Repository-local value:
To see where a value is coming from, this is even better:
That tells you both the value and the config file that defines it.
Change the Username Globally
If you want the new name to apply to all repositories on the machine by default:
You usually also want the matching email:
These commands update your global Git config, typically in ~/.gitconfig.
Change the Username for One Repository Only
If you want a different identity for just one project, run the command inside that repository without --global.
This writes to that repository's .git/config and overrides the global identity for commits made there.
Verify the Result
After changing the setting, confirm it:
Or list all effective values:
That is especially useful when global and local settings overlap.
What Changes and What Does Not
Changing user.name affects future commits. It does not rewrite past commits.
If you make a new commit after changing the config, the new name appears in that commit's author metadata. Existing commit history remains unchanged unless you explicitly rewrite history.
That distinction matters because many people expect the command to "fix GitHub" or "rename old commits." It does not.
If the Wrong Name Still Appears
Common reasons include:
- a local repository config overrides the global value
- the commit was already created before the config change
- an IDE or GUI tool is using a different Git installation or config source
- environment variables are overriding config
Useful checks:
These commands help confirm which identity Git would use right now.
Author Versus Committer
Git tracks both author and committer identity. For ordinary local work, they are usually the same. But in rebases, cherry-picks, or patched workflows, the committer identity can differ from the original author.
That is another reason to inspect actual commit metadata rather than assuming the config change solved every visible identity issue everywhere.
Rewriting Old Commits Is a Separate Task
If your real goal is to change the name on existing commits, that is history rewriting, not config editing. The tools for that are different and much riskier, especially on shared branches.
For most users, changing user.name is only the correct fix for future commits.
Common Pitfalls
- Setting the global name and forgetting a repository-local override still exists.
- Expecting the change to rewrite old commits automatically.
- Changing the username but not the matching email address.
- Debugging GitHub display issues before checking the actual local commit metadata.
- Using an IDE with a different Git config source than the terminal session.
Summary
- Use
git config --global user.name "Your Name"to change the default name for all repositories. - Use
git config user.name "Your Name"inside one repository for a local override. - Verify with
git config --show-origin --get user.name. - The change affects future commits only.
- If the wrong identity still appears, check for local overrides and inspect the actual author and committer values.
Related reading
- How to change the default target branch for merges in Gitlab
- How to change the remote a branch is tracking?
- How to change the remote a branch is tracking?
- How to change the remote repository for a git submodule?
- How to change the remote repository for a git submodule?
- How to check for changes on remote origin Git repository
- How to checkout in Git by date?
- How to checkout old git commit including all submodules recursively?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.