Custom git config per directory tree

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

comments powered by Disqus

Related Posts

Hamclock - A useful tool for your shack

Hamclock - A useful tool for your shack

When it comes to the world of amateur radio, there is a lot of software out there, you can use to make your life a little bit more pleasant - Hamclock is exactly that.

Read More

LazyVim? Good or bad idea?

I recently started to use vim and fiddled around with creating my own configs and others.

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

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

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