less than 1 minute read

Using git in both work and home, being able to configure the environment efficiently depending on what I’m doing is critical.

includeIf to the rescue.

The includeIf section in a .gitconfig allow you to include config directives from another source. includeIf sections may be ignored if their condition does not evaluate to true.

This allows me to define my .gitconfig in a manner that applies the appropriate configuration depending on whether I’m in a personal or work directory.

[core]
	excludesfile = /Users/doneill/.gitignore_global
[credential]
	helper = osxkeychain
[pull]
	rebase = false
[user]
	name = Damian ONeill
[includeIf "gitdir:~/projects/personal/"]
    path = .gitconfig-personal
[includeIf "gitdir:~/projects/work/"]
    path = .gitconfig-work

As can be seen above, I have some common config that gets applied regardless of the current directory structure, then either personal or work configuration that gets applied when I’m the corresponding directory tree.

Tags: ,

Categories:

Updated: