Your Git username and email are essential for tracking who makes changes in a repository. If you need to correct your identity, change accounts, or switch contexts (e.g., work vs. personal), Git makes it easy to update these credentials.
This guide shows you how to update your Git username
and email
both globally and per project.
β Check Current Git Config
To view your current Git configuration:
git config --list
Look for these two lines:
user.name=Your Name
user.email=yo**@em***.com
π Change Git Username and Email (Global)
This updates your identity for all repositories on your machine:
git config --global user.name "Your New Name"
git config --global user.email "yo*****@em***.com"
Example:
git config --global user.name "Jane Doe"
git config --global user.email "ja******@ex*****.com"
π Change Git Username and Email (Per Repository)
To update your identity only in a specific repository:
- Navigate to your repository:
cd path/to/your-repo
- Set local config:
git config user.name "Your New Name" git config user.email "yo*****@em***.com"
These settings will override the global ones only for that repo.
π Verify the Changes
To confirm your updates:
git config user.name
git config user.email
Or, to check global values:
git config --global user.name
git config --global user.email
π Note: This Does Not Change Past Commits
Changing your Git config only affects future commits. If you want to change the author info of previous commits, you’ll need to rewrite history using commands like git rebase
or git commit --amend
(used with caution).
β Summary
Scope | Command Example |
---|---|
Global config | git config --global user.name "Your Name" |
Local (repo) | git config user.name "Your Name" |
Check config | git config --list |
π Conclusion
Keeping your Git username and email accurate ensures proper commit attribution and helps collaborators identify your contributions. Whether you’re updating your info globally or for a specific repo, Git makes the process quick and easy.