Can gitconfig options be set conditionally?

You can conditionally include another Git config file based on your Git directory or branch in Git 2.13 and later.

Put your default configuration in file ~/.gitconfig as usual. At the end, conditionally include another configuration file:

[user]
    email = john@personal.com
    name = John McGehee

# All work Git repositories are in a subdirectory of ~/work.
# All other Git repositories are outside ~/work.
[includeIf "gitdir:~/work/"]
    path = .gitconfig.work

Then, in ~/.gitconfig.work add or override configuration values you want when using a repository located in ~/work or any subdirectory thereof:

[user]
    email = john@work.com

You can observe the difference by changing to a Git directory under ~/work, and running:

git config user.email

Try the same command in a Git directory that is not under ~/work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)