Git
username
terminal
command line
tutorial

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.

Browse interview questions

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:

bash
git config --global user.name

Repository-local value:

bash
git config --local user.name

To see where a value is coming from, this is even better:

bash
git config --show-origin --get user.name

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:

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

You usually also want the matching email:

bash
git config --global user.email "[email protected]"

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.

bash
cd /path/to/repo
git config user.name "Work Identity"
git config user.email "[email protected]"

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:

bash
git config user.name
git config user.email

Or list all effective values:

bash
git config --list --show-origin

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:

bash
git config --show-origin --get user.name
git var GIT_AUTHOR_IDENT
git var GIT_COMMITTER_IDENT

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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.