Custom git config per directory tree

Table of Contents

I usually am allowed to use my work computer privately as well, so often I find myself coding away on a sideproject in the evening without switching to another machine. Or I found a really cool thing I wanted to try out.

More than once I accidentally committed to a private project using the wrong Git config, so my work email was in those commits. Not really cool and I always tried to make sure to have a custom git config per private project.

However, today I’ve learnt: You can specify a git config per directory tree. Means: My work code gets my work config and my private stuff gets my private config. And if I want to code some hamradio stuff, I can have another ID that shows my callsign rather than my name. Or if I code on my super secret projects I do want to have affiliated with my alter ego (I really don’t have one, this is all hypothetical, or is it?) that has no ties to my real name.

The method really is straight forward. The following lines in your ~/.gitconfig have you covered:

[includeIf "gitdir:~/work/dev/"]
  path = ~/.config/gitconfig-workstuff
[includeIf "gitdir:~/private/dev/"]
  path = ~/.config/gitconfig-private
[includeIf "gitdir:~/alterego/dev/"]
  path = ~/.config/gitconfig-s3cr3tsq41rr37

Go and watch the great “So you think you know git” video

Share :

Related Posts

Git - It's not that hard and will 🚀 your workflow!

Git has been around for over 15 years now, and it is the go to tool for almost all developers. However many novice developers struggle to learn how to code and …

Read More
An introduction into amateur radio and why YOU should pick it up as well ...

An introduction into amateur radio and why YOU should pick it up as well ...

You might have heard about a technology called radio. In fact youre using it on a daily base, it’s omnipresent in our modern world.

Read More
An introduction into amateur radio and why YOU should pick it up as well ... outdoor edition

An introduction into amateur radio and why YOU should pick it up as well ... outdoor edition

Outdoors you will encounter areas without any cellpone service. Places you may actively look for in order to get away from the stress of your daily grind. …

Read More