JB

Git Config By Directory

How to configure git configurations based on the active pwd

Something that I sadly have had to do way too many times this year. I should stop reformatting my laptop lol.

Create ~/.gitconfig

The format is:

$ cat ~/.gitconfig 
[includeIf "gitdir:~/Projects/gitlab/"]
    path = ~/.config/git/gitlab.conf

Then create your git configurations in the correct place:

/home/x/.config/git/
├── gitlab.conf
└── github.conf
$ cat ~/.config/git/gitlab.conf 
[user]
	name  = myname
	email = myemail

You need the trailing / in the gitdir Otherwise it doesn’t work.