How to set different git config user.email and user.name for work and personal at a folder level
- Posted in:
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 "email@example.com"
C:\>git config --global user.name Arun Endapally
C:\>git config --global user.email firstname.lastname@example.org
Whenever we clone a public repository or start our own personal repository, we would like to use our personal name and email instead of companies and it becomes very irritating for setting 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 "email@example.com"
C:\my-repo>git config user.name Arun
C:\my-repo>git config user.email firstname.lastname@example.org
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.
In .gitconfig, update as below.
[user] email = email@example.com name = Arun Endapally [includeIf "gitdir/i:C:/Personal"] path = .gitconfig-personal
Note: You should add includeIf to bottom as highlighted in yellow, 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 = firstname.lastname@example.org
Now go ahead and test your setting, now 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 and as below.
C:\personal>git config user.name Arun Endapally C:\personal>git config user.email email@example.com C:\personal>cd c:/work c:\work>git config user.name Arun Endapally c:\work>git config user.email firstname.lastname@example.org
Enjoy! please share it with your friends and colleagues, if you liked it.
Good Work !!Vinna
Good onesaneeta narla
this command will show the origin of the gitconfig and email "git config --show-origin --get user.email"Arun Endapally