Search code examples
gitgit-config

Can a global .gitconfig file be nested multiple layers deep?


All the examples I've seen of global .gitconfig files look something like this:

[user]
    name = John Doe
    email = [email protected]

[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true

I've never seen a [header] nested within another [header] before. Something like this:

[user]
    name = John Doe
    email = [email protected]
    [foo]
        bar = baz

Is this possible in some circumstance? Can a global .gitconfig file be nested multiple layers deep?


Solution

  • The syntax for Git configuration files is a modified INI-file syntax.

    Some modified-INI-file-syntaxes (or syntaces, if you want to fake up an English plural from Greek roots) allow that sort of nesting, but Git's does not.

    In the Git form:

    [top "middle"]
        bottom = value
    

    represents the git config construct:

    git config top.middle.bottom value
    

    (add --global or --file directives to choose a file to set). This is as close as we get to nesting. You'll see these with multiple remote definitions, for instance:

    [remote "origin"]
        url = ...
        fetch = +refs/heads/*:refs/remotes/origin/*
    [remote "upstream"]
        url = ...
        fetch = +refs/heads/*:refs/remotes/upstream/*
    

    in the local .git/config file.