Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Elsie Hupp <git@elsiehupp.com>
To: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
	reto@labrat.space, philipoakley@iee.email, git@vger.kernel.org
Subject: Re: Multiple --global config workspaces?
Date: Tue, 11 Oct 2022 12:55:24 -0400	[thread overview]
Message-ID: <03B277AB-DE33-443D-AC9C-FAB7A2F93AB3@elsiehupp.com> (raw)
In-Reply-To: <Y0Vr/4IeA236nxzF@coredump.intra.peff.net>

Hi Junio, Reto, Jeff, Philip, et al,

Cool, thanks!

I was using the “Git Book” documentation, not the manpage, since (a) the “Git Book” is more user-friendly, and (b) it’s higher on the DuckDuckGo results for “git config", i.e.:

https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

Even then, I don’t see includeIf in the first two web-based versions of the manpage for the DuckDuckGo query "man git-config":

https://linux.die.net/man/1/git-config
https://manpages.org/git-config

Though includeIf does appear in the manpage on my local system, as well as in the web-based Arch manpage (which is the fifth result):

https://man.archlinux.org/man/git-config.1

And includeIf does appear in the official documentation (which is the first DuckDuckGo result for "man git-config”—I much prefer web mirrors to using man in the terminal):

https://git-scm.com/docs/git-config#_conditional_includes

So in summary it seems like a big part the issue I had is that the documentation for conditional includes has somewhat lacking SEO, i.e. if someone is familiar with the --global config keywords and googles that, they are unlikely to find the section for conditional includes. And, additionally, conditional includes are a new enough feature that they don’t appear in the higher-ranking web-based manpages, neither of which display the version of Git they pertain to. (Maybe someone could poke them about this, but I’m not sure the best way of doing so.)

As an aside, looking through the full documentation I see that I can also do:

[includeIf "hasconfig:remote.*.url:https://github.com/**”] path = ./Repositories/github/.gitconfig
[includeIf "hasconfig:remote.*.url:https://gitlab.com/**”] path =  ./Repositories/gitlab/.gitconfig

And, conveniently, [includeIf "gitdir:github/“] also expands to [includeIf “gitdir:**/github/“], so I don’t have to specify [includeIf "gitdir:~/Repositories/github/“]. (I’m not sure how to represent the trailing slash in bash syntax, but it helps, too!)

Something more consistent with my initial use case might be a hypothetical feature like the following (apologies for dubious syntax):

[user "gitdir:github/"]
	email = "elsiehupp.github@example.com"

Or something like:

if "gitdir:gitlab/" email = "elsiehupp.gitlab@example.com”

In other words, part of the discoverability issue is that I wasn’t looking for a conditional _include_ so much as a conditional statement more generally.

I also tried:

[include] path = $GIT_COMMON_DIR/../.gitconfig

…only to discover that $GIT_COMMON_DIR is not set automatically. Is there some way of automatically describing a path relative to any given cloned Git repository?

And I tried the following to no avail (despite both paths resolving when using cat):

[includeIf "gitdir:github/"] path = ./**/github/.gitconfig

[includeIf "gitdir:github/"] path = ./*/github/.gitconfig

So it would be nice if in addition to being able to use bash wildcards in [includeIf “gitdir”] one could use bash wildcards in inclusion paths, as well.

I guess for the time being what I’ll stick with is this:

[includeIf "gitdir:github/"] path = ./Repositories/github/.gitconfig
[includeIf "gitdir:gitlab/"] path = ./Repositories/gitlab/.gitconfig

Best,
Elsie Hupp


> On Oct 11, 2022, at 9:56 AM, Philip Oakley <philipoakley@iee.email> wrote:
> 
> On 11/10/2022 06:50, Junio C Hamano wrote:
>> Elsie Hupp <git@elsiehupp.com> writes:
>> 
>>> I structure my cloned repositories based on the remote host, e.g.:
>>> 
>>> ~/Repositories/github/cloned-repository-name
>>> ~/Repositories/gitlab/other-cloned-repository-name
>> The above is by definition not "global" (aka "per user").
>> 
>> "--global" is for things that are of your personal preference, not
>> "when I am working on this project, these settings apply" (which is
>> suitable for "per repository").
>> 
>> What you want is a way to say "when I am working on these projects,
>> these settings apply".
>> 
>> One way to do this would be to have
>> 
>> 	[includeIf "gitdir:~/Repositories/github/"] path = $HOME/.githubconfig
>> 	[includeIf "gitdir:~/Repositories/gitlab/"] path = $HOME/.gitlabconfig
>> 
>> in $HOME/.gitconfig and then write in these two extra files that are
>> conditionally included whatever settings you want to use for any and
>> all repositories that come from GitHub or GitLab.
>> 
>> $ git help config
>> 
>> and look for Conditional includes, perhaps?
>> 
>> 
> This use of "IncludeIf" for the Home/work case also came up in a recent
> Git for Windows discussion
> https://github.com/git-for-windows/git/discussions/4058
> 
> That discussion was about the trickiness of quoting when on the
> different Windows terminals/shells as the config string gets passed
> around (IIUC).
> 
> --
> Philip



> On Oct 11, 2022, at 1:50 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Elsie Hupp <git@elsiehupp.com> writes:
> 
>> I structure my cloned repositories based on the remote host, e.g.:
>> 
>> ~/Repositories/github/cloned-repository-name
>> ~/Repositories/gitlab/other-cloned-repository-name
> 
> The above is by definition not "global" (aka "per user").
> 
> "--global" is for things that are of your personal preference, not
> "when I am working on this project, these settings apply" (which is
> suitable for "per repository").
> 
> What you want is a way to say "when I am working on these projects,
> these settings apply".
> 
> One way to do this would be to have
> 
> 	[includeIf "gitdir:~/Repositories/github/"] path = $HOME/.githubconfig
> 	[includeIf "gitdir:~/Repositories/gitlab/"] path = $HOME/.gitlabconfig
> 
> in $HOME/.gitconfig and then write in these two extra files that are
> conditionally included whatever settings you want to use for any and
> all repositories that come from GitHub or GitLab.
> 
> $ git help config
> 
> and look for Conditional includes, perhaps?


> On Oct 11, 2022, at 1:51 AM, Reto <reto@labrat.space> wrote:
> 
> That already exists, git-config(1), look for "Conditional includes"
> That way you can do it per top level folder or whatever makes sense for
> you.
> 
> Examples:
> 
> ; include for all repositories inside /path/to/group
> [includeIf "gitdir:/path/to/group/"]
> 	   path = /path/to/foo.inc
> 
> ; include for all repositories inside $HOME/to/group
> [includeIf "gitdir:~/to/group/"]
> 	   path = /path/to/foo.inc


> On Oct 11, 2022, at 9:13 AM, Jeff King <peff@peff.net> wrote:
> 
> On Mon, Oct 10, 2022 at 10:50:22PM -0700, Junio C Hamano wrote:
> 
>> One way to do this would be to have
>> 
>> 	[includeIf "gitdir:~/Repositories/github/"] path = $HOME/.githubconfig
>> 	[includeIf "gitdir:~/Repositories/gitlab/"] path = $HOME/.gitlabconfig
>> 
>> in $HOME/.gitconfig and then write in these two extra files that are
>> conditionally included whatever settings you want to use for any and
>> all repositories that come from GitHub or GitLab.
> 
> I was about to write the same response. :) One small correction, though:
> we don't expand $HOME in include paths. You can use "~", but easier
> still is that non-absolute includes are relative to the including file.
> Relative paths in includes are relative to the including file. So you
> can just write ".githubconfig", etc, and we'll expect them adjacent to
> $HOME/.gitconfig (or the xdg path if you use that, I guess).
> 
> -Peff


  reply	other threads:[~2022-10-11 16:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11  3:06 Multiple --global config workspaces? Elsie Hupp
2022-10-11  5:50 ` Junio C Hamano
2022-10-11 13:13   ` Jeff King
2022-10-11 16:55     ` Elsie Hupp [this message]
2022-10-11 18:41       ` Elsie Hupp
2022-10-14 19:39       ` Jeff King
2022-10-15 10:56         ` Matthias Aßhauer
2022-10-15 18:14           ` Jeff King
2022-10-18  4:02         ` Elsie Hupp
2022-10-18 20:53           ` Jeff King
2022-10-20  2:29             ` Elsie Hupp
2022-10-20  2:39               ` Elsie Hupp
2022-10-11 13:56   ` Philip Oakley
2022-10-11  5:51 ` Reto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03B277AB-DE33-443D-AC9C-FAB7A2F93AB3@elsiehupp.com \
    --to=git@elsiehupp.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=philipoakley@iee.email \
    --cc=reto@labrat.space \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).