How to Configure Different Git User Info for Each Repository on One Machine
This guide explains why configuring Git user name and email at the repository level is essential when working on both personal and corporate projects on the same computer, and provides step‑by‑step commands to set, verify, and manage these settings effectively.
When developing on a single machine for both personal and corporate projects, Git uses the configured user name and email to label each commit. Properly separating these identities prevents confusing commit histories and improves team collaboration.
Why Configure User Info at the Repository Level?
Using a single global configuration makes all commits appear under the same identity, which can mix personal and company contributions. Distinguishing the two ensures clear attribution in the project history.
Git Configuration Levels
Global : applies to every repository for the current user.
Repository : applies only to the current repository.
System : applies to all users on the system.
Step 1: Set Global User Information
git config --global user.name "Your Name"
git config --global user.email "[email protected]"This establishes default values used by all repositories unless overridden locally.
Step 2: Set Repository‑Level User Information
Navigate to the target repository and run:
cd /path/to/your/repo
git config user.name "Company Name"
git config user.email "[email protected]"These settings affect only this repository, leaving other repositories untouched.
Step 3: Verify Current Repository Configuration
git config --listCheck the output for user.name and user.email to confirm the correct values are applied.
Step 4: Switch Configurations Between Repositories
If you frequently switch between projects, you can script the configuration or edit each repository’s .git/config directly:
git config --file /repo/.git/config user.name "Company Name"
git config --file /repo/.git/config user.email "[email protected]"This ensures the repository‑level settings override the global ones.
Best Practices
Separate Personal and Company Projects : Use distinct names and emails for each to keep commit logs clear.
Avoid Overriding Repository Settings with Global Config : Apply global settings only when the same identity is used across all projects.
Regularly Check Configuration : Run git config --list to verify settings and maintain consistency.
Use Git Hooks : Implement pre-commit or commit-msg hooks to enforce correct user information on each commit.
Conclusion
Properly configuring Git user information at both global and repository levels ensures that each project's commit history remains accurate and traceable, preventing mixed identities and enhancing development efficiency and team collaboration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development & AI Practice
DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
