* git config: unintuitive behaviour with --global and --no-includes
@ 2026-07-20 9:34 Hendrik Jaeger
2026-07-20 12:25 ` Ben Knoble
2026-07-20 12:51 ` Jeff King
0 siblings, 2 replies; 5+ messages in thread
From: Hendrik Jaeger @ 2026-07-20 9:34 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 4788 bytes --]
Hi
I ran into a problem working with lbmk (https://codeberg.org/libreboot/lbmk).
To see whether git is correctly configured, it runs `git config --global user.name` and that failed for my setup.
The reason is that I have user.name and user.email not directly in the normal git config file but in an included file and when given a scope like --global `git config` does not by default check included files.
I tried to create a commented minimal example showing the problem with that:
```
# no config exists
~ % cat .gitconfig
cat: .gitconfig: No such file or directory
~ % cat .gitconfig_personal
cat: .gitconfig_personal: No such file or directory
~ % ls ~/.config/git
ls: cannot access '/home/resu/.config/git': No such file or directory
# config var is not set
~ % git config --show-scope --show-origin user.name
# set user.name
~ % git config --global user.name "Hendrik Jäger"
# check if it is set
~ % cat .gitconfig
[user]
name = Hendrik Jäger
# check where it is set
~ % git config --show-scope --show-origin user.name
global file:/home/resu/.gitconfig Hendrik Jäger
# check whether we can still retrieve it when explicitly giving the scope
~ % git config --show-scope --show-origin --global user.name
global file:/home/resu/.gitconfig Hendrik Jäger
# move setting to non-standard file
~ % cat .gitconfig > .gitconfig_personal
# include that non-standard file
~ % echo '[include]\npath = .gitconfig_personal' >| .gitconfig
# check config status
~ % cat .gitconfig
[include]
path = .gitconfig_personal
~ % cat .gitconfig_personal
[user]
name = Hendrik Jäger
# check whether git still finds that setting
~ % git config --show-scope --show-origin user.name
global file:/home/resu/.gitconfig_personal Hendrik Jäger
# check whether git still finds that setting in the scope it is in
~ % git config --show-scope --show-origin --global user.name
# set it again in the global scope
~ % git config --global user.name "Henk Hunter"
# check again
~ % git config --show-scope --show-origin user.name
global file:/home/resu/.gitconfig Henk Hunter
# check again with specific scope
~ % git config --show-scope --show-origin --global user.name
global file:/home/resu/.gitconfig Henk Hunter
# reset git config and check if the setting is really gone
~ % rm .gitconfig
~ % git config --show-scope --show-origin user.name
# set it again in global scope with different value
~ % git config --global user.name "Henk Hunter"
# check whether setting it was successful
~ % git config --show-scope --show-origin user.name
global file:/home/resu/.gitconfig Henk Hunter
# check again with specific scope
~ % git config --show-scope --show-origin --global user.name
global file:/home/resu/.gitconfig Henk Hunter
# add the include back
~ % echo '[include]\npath = .gitconfig_personal' >> .gitconfig
# check config status
~ % cat .gitconfig
[user]
name = Henk Hunter
[include]
path = .gitconfig_personal
# check the value and from which scope it comes
~ % git config --show-scope --show-origin user.name
global file:/home/resu/.gitconfig_personal Hendrik Jäger
# check again with specific scope
~ % git config --show-scope --show-origin --global user.name
global file:/home/resu/.gitconfig Henk Hunter
# check again while allowing includes
~ % git config --show-scope --show-origin --includes user.name
global file:/home/resu/.gitconfig_personal Hendrik Jäger
~ % git config --show-scope --show-origin --global --includes user.name
global file:/home/resu/.gitconfig_personal Hendrik Jäger
```
The manpage says:
> Respect include.* directives in config files when looking up values. Defaults to off when a specific file is given (e.g., using --file, --global, etc) and on when searching all config files.
IMHO it makes sense the way it is phrased “when a specific file is given” but then seems to turn into non-sense when --global is given as an example. Giving --global is not “giving a specific file” but “restricting to a specific scope”, which may `include` other files.
The results seem inconsistent and counterintuitive to me.
Am I misunderstanding anything here?
Is this behaviour intended?
If it is intended, can someone please explain the rationale behind it? I don’t get it, it seems wrong to me.
Regarding the initial issue: I just added --includes to the call in lbmk and it works just fine, so there is no need to address this. I only mentioned it for context to how I got to looking into this behaviour.
If any relevant information is missing in this bugreport, I’ll be happy to add it, please let me know!
Thank you very much
henk
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: git config: unintuitive behaviour with --global and --no-includes 2026-07-20 9:34 git config: unintuitive behaviour with --global and --no-includes Hendrik Jaeger @ 2026-07-20 12:25 ` Ben Knoble 2026-07-20 12:51 ` Jeff King 1 sibling, 0 replies; 5+ messages in thread From: Ben Knoble @ 2026-07-20 12:25 UTC (permalink / raw) To: Hendrik Jaeger; +Cc: git > Le 20 juil. 2026 à 06:02, Hendrik Jaeger <ml_git@henk.geekmail.org> a écrit : > > Hi > > I ran into a problem working with lbmk (https://codeberg.org/libreboot/lbmk). > To see whether git is correctly configured, it runs `git config --global user.name` and that failed for my setup. > The reason is that I have user.name and user.email not directly in the normal git config file but in an included file and when given a scope like --global `git config` does not by default check included files. [snip] > Regarding the initial issue: I just added --includes to the call in lbmk and it works just fine, so there is no need to address this. I wonder why not use « git config user.name » without scope? That seems to sidestep the problem. Unless there’s a reason to use global-scope only? There’s also « git var GIT_AUTHOR_IDENT ». ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git config: unintuitive behaviour with --global and --no-includes 2026-07-20 9:34 git config: unintuitive behaviour with --global and --no-includes Hendrik Jaeger 2026-07-20 12:25 ` Ben Knoble @ 2026-07-20 12:51 ` Jeff King 2026-07-20 17:09 ` Junio C Hamano 2026-07-21 11:53 ` Hendrik Jaeger 1 sibling, 2 replies; 5+ messages in thread From: Jeff King @ 2026-07-20 12:51 UTC (permalink / raw) To: Hendrik Jaeger; +Cc: git On Mon, Jul 20, 2026 at 11:34:02AM +0200, Hendrik Jaeger wrote: > The manpage says: > > Respect include.* directives in config files when looking up > > values. Defaults to off when a specific file is given (e.g., using > > --file, --global, etc) and on when searching all config files. > > IMHO it makes sense the way it is phrased “when a specific file is > given” but then seems to turn into non-sense when --global is given as > an example. Giving --global is not “giving a specific file” but > “restricting to a specific scope”, which may `include` other files. > The results seem inconsistent and counterintuitive to me. > > Am I misunderstanding anything here? > Is this behaviour intended? > If it is intended, can someone please explain the rationale behind it? I don’t get it, it seems wrong to me. The behavior you're seeing is intended. Regarding "a specific scope", I don't think that's an unreasonable way to think about it. But it's not how Git thinks about it, and in particular back when --include was added and this behavior was set, "--global" was literally a synonym for "--file=$HOME/.gitconfig". As for the rationale, it is a mix of backwards compatibility and least-surprise. The include functionality was tacked on to the existing config parser, and we did not want to surprise anybody who asked for a specific file by showing them results for another file. This is especially important for reading untrusted input like .gitmodules, but also for writing. > Regarding the initial issue: I just added --includes to the call in > lbmk and it works just fine, so there is no need to address this. I > only mentioned it for context to how I got to looking into this > behaviour. IMHO lbmk is wrong to be using "--global" in the first place. Looking at the source, it is trying to check whether the user has set up their identity. But it is not lbmk's business whether you did it in the --global config file, or elsewhere! So it should probably just use a straight "git config user.name", which will do the same resolution that Git will do internally. The "--global" was added in their 4a280c62 (.gitcheck: re-write entirely. force global config., 2023-08-27), but I don't see any rationale given. Depending on what they are trying to check, it might be even better still for it to use "git var GIT_AUTHOR_IDENT". That will give the actual ident Git will derive, including things like checking $EMAIL in the environment and so on. So if the intent is "will Git come up with some ident", then that is the most accurate way to check it. But if the intent is "did the user specifically configure Git (because we are worried that values derived from GECOS and $EMAIL might not be accurate)", then checking user.* specifically is closer to that. Though note there is one other hitch, which is that the user can set author.* and committer.* as specific variables, since 39ab4d0951 (config: allow giving separate author and committer idents, 2019-02-04). I suspect not many people do that, but that would also be something that a config-specific check would have to handle (but "git var" would do automatically). So I think you might consider sending a bug report to lbmk. Feel free to point at this thread, and I'm happy to discuss further with them. -Peff ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git config: unintuitive behaviour with --global and --no-includes 2026-07-20 12:51 ` Jeff King @ 2026-07-20 17:09 ` Junio C Hamano 2026-07-21 11:53 ` Hendrik Jaeger 1 sibling, 0 replies; 5+ messages in thread From: Junio C Hamano @ 2026-07-20 17:09 UTC (permalink / raw) To: Jeff King; +Cc: Hendrik Jaeger, git Jeff King <peff@peff.net> writes: > IMHO lbmk is wrong to be using "--global" in the first place. Looking at > the source, it is trying to check whether the user has set up their > identity. But it is not lbmk's business whether you did it in the > --global config file, or elsewhere! Exactly. > Though note there is one other hitch, which is that the user can set > author.* and committer.* as specific variables, since 39ab4d0951 > (config: allow giving separate author and committer idents, 2019-02-04). > I suspect not many people do that, but that would also be something that > a config-specific check would have to handle (but "git var" would do > automatically). > > So I think you might consider sending a bug report to lbmk. Feel free to > point at this thread, and I'm happy to discuss further with them. Thanks for your thoughtful and thorough explanation. The environment variables 'GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL}' also play a part in determining the author andcommitter identities, so 'git var AUTHOR_IDENT' would be the correct choice here. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: git config: unintuitive behaviour with --global and --no-includes 2026-07-20 12:51 ` Jeff King 2026-07-20 17:09 ` Junio C Hamano @ 2026-07-21 11:53 ` Hendrik Jaeger 1 sibling, 0 replies; 5+ messages in thread From: Hendrik Jaeger @ 2026-07-21 11:53 UTC (permalink / raw) To: Jeff King; +Cc: git [-- Attachment #1: Type: text/plain, Size: 3984 bytes --] Hi Jeff Thanks for your email! > As for the rationale, it is a mix of backwards compatibility and least-surprise. To be honest, this reminds me of the XKCD comic with the title "workflow": https://xkcd.com/1172/ The behaviour may be “least-surprise” for the initiated. For everyone new to this, I’d expect it to be as “most-surprising” as it was for me. Best regards henk On Mon, 20 Jul 2026 08:51:45 -0400 Jeff King <peff@peff.net> wrote: > On Mon, Jul 20, 2026 at 11:34:02AM +0200, Hendrik Jaeger wrote: > > > The manpage says: > > > Respect include.* directives in config files when looking up > > > values. Defaults to off when a specific file is given (e.g., using > > > --file, --global, etc) and on when searching all config files. > > > > IMHO it makes sense the way it is phrased “when a specific file is > > given” but then seems to turn into non-sense when --global is given as > > an example. Giving --global is not “giving a specific file” but > > “restricting to a specific scope”, which may `include` other files. > > The results seem inconsistent and counterintuitive to me. > > > > Am I misunderstanding anything here? > > Is this behaviour intended? > > If it is intended, can someone please explain the rationale behind it? I don’t get it, it seems wrong to me. > > The behavior you're seeing is intended. Regarding "a specific scope", I > don't think that's an unreasonable way to think about it. But it's not > how Git thinks about it, and in particular back when --include was added > and this behavior was set, "--global" was literally a synonym for > "--file=$HOME/.gitconfig". > > As for the rationale, it is a mix of backwards compatibility and > least-surprise. The include functionality was tacked on to the existing > config parser, and we did not want to surprise anybody who asked for a > specific file by showing them results for another file. This is > especially important for reading untrusted input like .gitmodules, but > also for writing. > > > Regarding the initial issue: I just added --includes to the call in > > lbmk and it works just fine, so there is no need to address this. I > > only mentioned it for context to how I got to looking into this > > behaviour. > > IMHO lbmk is wrong to be using "--global" in the first place. Looking at > the source, it is trying to check whether the user has set up their > identity. But it is not lbmk's business whether you did it in the > --global config file, or elsewhere! So it should probably just use a > straight "git config user.name", which will do the same resolution that > Git will do internally. > > The "--global" was added in their 4a280c62 (.gitcheck: re-write > entirely. force global config., 2023-08-27), but I don't see any > rationale given. > > Depending on what they are trying to check, it might be even better > still for it to use "git var GIT_AUTHOR_IDENT". That will give the > actual ident Git will derive, including things like checking $EMAIL in > the environment and so on. > > So if the intent is "will Git come up with some ident", then that is the > most accurate way to check it. But if the intent is "did the user > specifically configure Git (because we are worried that values derived > from GECOS and $EMAIL might not be accurate)", then checking user.* > specifically is closer to that. > > Though note there is one other hitch, which is that the user can set > author.* and committer.* as specific variables, since 39ab4d0951 > (config: allow giving separate author and committer idents, 2019-02-04). > I suspect not many people do that, but that would also be something that > a config-specific check would have to handle (but "git var" would do > automatically). > > So I think you might consider sending a bug report to lbmk. Feel free to > point at this thread, and I'm happy to discuss further with them. > > -Peff [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-21 11:53 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-20 9:34 git config: unintuitive behaviour with --global and --no-includes Hendrik Jaeger 2026-07-20 12:25 ` Ben Knoble 2026-07-20 12:51 ` Jeff King 2026-07-20 17:09 ` Junio C Hamano 2026-07-21 11:53 ` Hendrik Jaeger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox