git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Why does the includeif woks how it does?

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Feb 19, 2024, 20:10 UTC
Message-ID
<ZdO1oL73SF5ZKOJT@tapette.crustytoothpaste.net>
In-Reply-To
<FR2P281MB1686B7258CFB60A0F33FE108BA522@FR2P281MB1686.DEUP281.PROD.OUTLOOK.COM>
On 2024-02-18 at 15:37:29, Dominik von Haller wrote:
Show 7 quoted lines
> I have been playing around with the includeif from the .gitconfig. It did not work for me at first, but after some help, I did get it to work.
> 
> If you are curious. My Problem and what else was discussed here: https://github.com/git-for-windows/git/issues/4823
> 
> Anyway. So, I was trying to access the email property which was set through an includeif config. It did not work because I was in a non git directory. Yes, I do know that the property set in includeif is named gitdir, but it was not obvious to me that you need to be in a git tracked directory for it to work.
> 
> I am trying to understand why it must be this way. Why does it not work in non git tracked directories?

The main reason it works this way is because the goal is to adjust configuration based on the location of a repository. Thus, if I have `~/checkouts/work/` with my work code and `~/checkouts/personal/` with my personal code, I can set options that are appropriate in each case (e.g., `user.email`, `user.signingkey`, `credential.helper`, etc.).

Also, except for reading and writing with `git config`, the configuration is typically not used unless you're in a repository. There are only a handful of Git commands that don't use a repository at all, so usually setting configuration outside of a repository isn't very useful.

Note that if it didn't require a repository, then it would have to work on the current working directory. But, it should be noted, the gitdir option specifically does not operate on the current working directory. While it is customary to have one's working directory be inside the repository, you can be elsewhere and use `git -C` to change into the repository (internally, Git does indeed change the working directory, but that's an implementation detail).

That's not to say a feature couldn't be added that operated based on the current working directory (or some related constraint) instead, but no such feature has been added.

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Dominik von HallerNext: rsbecker@nexbridge.com
Message 2 of 4 in “Why does the includeif woks how it does?”
  1. Dominik von HallerFeb 18, 2024
  2. brian m. carlsonFeb 19, 2024
  3. rsbecker@nexbridge.comFeb 19, 2024
  4. Junio C HamanoFeb 20, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.