Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different .gitconfig for a given subdirectory?

I use two different git emails, one for work and one for public projects. Initially I thought that I could create a separate .gitconfig with a different email in a folder where all my public repos are in, and that git would respect that, but alas it seems that doesn't work. What's the best way to easily setup something similar? I want to avoid having to specifically change the email in each public repo.

like image 720
Suan Avatar asked Dec 01 '11 05:12

Suan


People also ask

Can I have multiple git configs?

With conditional includes in Git 2.13, it is now possible to have multiple user/email coexist on one machine with little work. user. gitconfig has my personal name and email.

What is subdirectory example?

Subdirectory URL In a URL, the subdirectory comes after the root directory or domain name. For example, HubSpot's root domain is hubspot.com. So a subdirectory URL might be hubspot.com/pricing. Or it might be something more complicated like hubspot.com/pricing/sales.


1 Answers

The best way to do this since git 2.13 is to use Conditional includes.

An example (copied from an answer here):

Global config ~/.gitconfig

[user]     name = John Doe     email = [email protected]  [includeIf "gitdir:~/work/"]     path = ~/work/.gitconfig 

Work specific config ~/work/.gitconfig

[user]     email = [email protected] 
like image 146
Chris Crewdson Avatar answered Sep 17 '22 17:09

Chris Crewdson