A repository of tips and tricks (in both English and French) curated by Mirego’s engineering team.
  • git

Conditional includes in git configuration file

I like keeping my personal settings and my work ones separated. One of the problem I had was mixing up my git user. If I forgot to configure the new work repo I just cloned, my personal email would be used in my commit signatures.

So, today I learned about conditional includes that can be used in .gitconfig to fix this issue.

# ~/.gitconfig
[includeIf "gitdir:/Volumes/Mirego/"]
  path = /Volumes/Mirego/.gitconfig

# /Volumes/Mirego/.gitconfig
  email = my-work-email@business.com

So now everytime I commit into any repository within /Volumes/Mirego/, my work email is used. Even on newly cloned repositories.