# Conditional git config includes

Sometimes we want to use different git configurations for different sub-directories. For client work, for example, we might want to use another email address for our commits. While this could be accomplished by modifying the local git configuration in each repository, there is another way to solve the problem in one stroke: conditional includes.

Using the `include` keyword, we can include other configuration files. With `includeIf`, we can supply a condition that must be met. There are many options, but one of the most useful ones is `gitdir`. If all work related projects are contained in a directory called `work` (be that in `~/work` or `~/dev/work` or somewhere else entirely), we can use this statement to include work-specific configuration for those projects:

```
[includeIf "gitdir:work/"]
  path = config-work
```

The path to the config file to include is relative to the main configuration file, unless an absolute path is given. Within it, we can override settings from the main file, e.g.:

```
[user]
  email = me@work.com
```

Source: `man git-config`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.eliasnorrby.com/git/config-conditional-includes-directory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
