Skip to content

MacOS: system gitconfig not recognized #6883

Open

Description

@jeroen

MacOS has some options stored in /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig by default.

It seems this is apple's GIT_CONFIG_LEVEL_SYSTEM however these are not found by git_config_open_default() or git_repository_config() in libgit2.

Somewhat interestingly, even git itself shows this config file as "unknown" on MacOS, so perhaps this is expected.

git config --show-origin --show-scope --list
# unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig   credential.helper=osxkeychain
# unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig   init.defaultbranch=main
# global  file:/Users/jeroen/.gitconfig   pull.rebase=true

Activity

  1. ethomson commented on Sep 18, 2024

    @ethomson
    Member

    Just to be clear - this is the git that comes with Xcode, correct? I know that it's a bit odd.

  2. jeroen commented on Sep 18, 2024

    @jeroen
    ContributorAuthor

    Technically it comes with the "xcode command line tools" app, which is separate from xcode, but yet it comes from apple.

  3. ethomson commented on Oct 23, 2024

    @ethomson
    Member

    Thanks. This seems like a thing that we should tackle.

  4. ethomson commented on Dec 11, 2024

    @ethomson
    Member

    I've thought about this a bit and ... I really just don't know what the right path forward here is.

    Apple ships some developer tools, like git, into /usr/bin, and just... does weird things to them. Like adding a custom configuration setting that adds behavior that makes sense but... is hard to reason about.

    unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig
    credential.helper=osxkeychain
    unknown file:/Library/Developer/CommandLineTools/usr/share/git-core/gitconfig
    init.defaultbranch=main
    

    This is strictly better than behavior of many years ago, where they would actually add things to git itself that made it behave in unpredictable ways.

    But if you were trying to build some tool, do you try to pay attention to this strange gitconfig, or no? Because other git installations (if you compiled from source, which I do, or if you installed from Homebrew, which a great many developers do) does not pay attention to those files.

    This situation similar, but a bit less bad, than the situation on Windows, where at least Git for Windows contributes changes back upstream, and is the canonical choice for git usage.

    I don't have a survey here, but I bet that git (as part of the Xcode / developer tools install) is not the most widely used git, I bet that's homebrew's version.

    So... what would you want? What should we do in the general case?

    My suspicion here is that we should have an opt-in option to read that file if it exists, and that we should not do that by default, but I'm (very) open to arguments.

  5. Aydin-ab commented on May 16, 2025

    @Aydin-ab

    Found this thread because I was also curious about that "unknown" scope.

    Since it's shipped by Apple, can't we just assume those settings are system-scoped? We could initialize a baseline config at /etc/gitconfig, as Git expects, and forget the original file.

    I prefer that default behavior, since most people are already using those settings without even realizing it. Unless you're deeply configuring Git or changing your credential helper, you'd probably never notice they're set at the system level (or acting like it).

    If it really bothers ppl, we could prompt users during Git installation to accept or reject those settings, then copy them to /etc/gitconfig, and forget the original file as before. I’m not a fan of that, Git is often the first command-line tool new developers install, and making them decide on obscure configuration setups like that can be intimidating/unfriendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions