How to Change Git Config Username and Email

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:

  1. Navigate to your repository: cd path/to/your-repo
  2. 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

ScopeCommand Example
Global configgit config --global user.name "Your Name"
Local (repo)git config user.name "Your Name"
Check configgit 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.

Sharing Is Caring:

Leave a Comment