git multiple user names for the different projects within the same system

GitGit Config

Git Problem Overview


I have a different git repository for my office and a different git repo for my hobby projects.

When I do git config --global user.name the user name changes globally and this creates a confusion of committing to a repo with user name.

Hence the question is how can i have the same username across all my hobby projects and the same username across the office projects. I use the same machine to work on both the places.

Git Solutions


Solution 1 - Git

Just use --local instead of --global. In fact, local is the default so you can just do

git config user.email [email protected]
git config user.name "whatf hobbyist"

in one repo, and

git config user.email [email protected]
git config user.name "whatf at work"

in another repo

The values will then be stored in in the .git/config for that repo rather than your global configuration file.

Solution 2 - Git

Omit the --global from your call to git config:

git config user.name "A. U. Thor"

This will set the property in the current repository.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwhatfView Question on Stackoverflow
Solution 1 - GitmikejView Answer on Stackoverflow
Solution 2 - GitBombeView Answer on Stackoverflow