Click here to Skip to main content
15,889,176 members
Articles / Repository
Technical Blog

How to Set Different Git Config user.email and user.name for Work and Personal at a Folder Level

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
14 Mar 2021Ms-PL1 min read 12.8K   6   3
Setting different Git Config at folder level for work and personal use.
Though we work on companies repositories mostly, sometimes we work on personal git repositories as well. In this post, we will see how to simplify this process by setting this information at the folder level rather than at the repository level.

We would be working on companies repositories mostly, but sometimes we would be working on personal git repositories as well. So ideally, we would be setting user.name and user.email globally with our company username and email as shown below:

C:\>git config --global user.name "Arun Endapally"
C:\>git config --global user.email "arun.endapally@work.com"
C:\>git config --global user.name
Arun Endapally
C:\>git config --global user.email
arun.endapally@work.com

Whenever we clone a public repository or start our own personal repository, we would like to use our personal name and email instead of company's and it becomes very irritating to set up this information each time at the repository level as shown below:

C:\my-repo>git config user.name "Arun"
C:\my-repo>git config user.email "arun.endapally@personal.com"
C:\my-repo>git config user.name
Arun
C:\my-repo>git config user.email
arun.endapally@personal.com

We can simplify this process by setting this information at the folder level. First, create a separate folder where you want to clone the public repos or start your personal repo, then open .gitconfig by entering .gitconfig in the run.

image_thumb1

In .gitconfig, update as below:

[user]
  email = arun.endapally@work.com
  name = Arun Endapally
[includeIf "gitdir/i:C:/Personal"]
   path = .gitconfig-personal

Note: You should add includeIf to bottom as highlighted in bold, order is important here. Now create a file with name .gitconfig-personal in C:/Personal and add your personal name and email to it as below:

[user]
    name = Arun Endapally
    email = arun.endapally@personal.com

Now go ahead and test your setting, you should see that the git repositories in the personal folder would use personal details while the rest of the folders would use work details as below:

C:\personal>git config user.name
Arun Endapally

C:\personal>git config user.email
arun.endapally@personal.com

C:\personal>cd c:/work

c:\work>git config user.name
Arun Endapally

c:\work>git config user.email
arun.endapally@work.com

Enjoy! If you liked it, please share it with your friends and colleagues, .

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Thomson Reuters
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUnfortunately didn't work for me Pin
PHenry17-Apr-21 9:00
PHenry17-Apr-21 9:00 
AnswerRe: Unfortunately didn't work for me Pin
PHenry17-Apr-21 9:23
PHenry17-Apr-21 9:23 
QuestionThanks for this example Pin
Garlon Arthur14-Mar-21 5:55
Garlon Arthur14-Mar-21 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.