Skip to content

git_sitrep() can report >1 value for the default default branch #2057

Open

Description

@jennybc

I discovered this in Windows Positron work. My Git for Windows installation has system-level config that sets init.defaultBranch to master. I have init.defaultBranch set to main at the user level. git_sitrep() shows this:

• Default initial branch name: "master" and "main"

which is weird!

The underlying issue is this:

dat <- gert::git_config_global()
subset(dat, name == "init.defaultbranch")
#>                  name  value  level
#> 10 init.defaultbranch master system
#> 13 init.defaultbranch   main global

I think I've never personally experienced this before because here's the same information on macOS:

dat <- gert::git_config_global()
subset(dat, name == "init.defaultbranch")
#>                 name value  level
#> 7 init.defaultbranch  main global

For the record, here are the Git versions in each location:

on macOS

git version 2.39.3 (Apple Git-145)

on Windows

git version 2.45.2.windows.1

so the Windows Git version is actually newer.

All that really matters is that usethis:::git_cfg_get() needs to account for this possibility, though:

usethis/R/utils-git.R

Lines 53 to 72 in 2cc9e5a

git_cfg_get <- function(name, where = c("de_facto", "local", "global")) {
where <- match.arg(where)
if (where == "de_facto") {
return(git_cfg_get(name, "local") %||% git_cfg_get(name, "global"))
}
if (where == "global" || !uses_git()) {
dat <- gert::git_config_global()
} else {
dat <- gert::git_config(repo = git_repo())
}
if (where == "local") {
dat <- dat[dat$level == "local", ]
}
out <- dat$value[tolower(dat$name) == tolower(name)]
if (length(out) > 0) out else NULL
}

Currently it seems to basically gloss over system config and only accounts for global and local.

Activity

  1. added
    bug
    git
    on Sep 12, 2024
  2. jennybc commented on Sep 13, 2024

    @jennybc
    MemberAuthor

    Interesting tidbit from macOS. It's true that gert::git_config_global() doesn't reveal any system config, but there does seem to be some:

    ~/rrr/usethis % 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/jenny/.gitconfig    user.name=Jenny Bryan
    global  file:/Users/jenny/.gitconfig    [email protected]
    global  file:/Users/jenny/.gitconfig    user.signingkey=/Users/jenny/.ssh/id_ed25519.pub
    ... and so on and so forth ...
    

    Notably this system config is labelled as "unknown", as opposed to "global" and "local" (or even "system").

  3. jeroen commented on Sep 18, 2024

    @jeroen
    Member

    Haven't tested this, but from the source it looks like git-for-windows lets the user choose the "system" value of init.defaultbranch during the installer process? So it is not specific to the version but rather to the vendor.

    I think the unknown config file was hacked in by apple's git build to override some defaults in xcode. Note the path of this config is inside git-core so it really seems specific to this build of command-line-git and not intended for other git versions or libraries. That would explain why libgit2 does not find it, but I'll ask upstream in libgit2: libgit2/libgit2#6883

  4. jennybc commented on Jul 24, 2025

    @jennybc
    MemberAuthor

    I have tinkered with this a bit, but it's actually hard to play with on macOS using Git from Xcode command line tools, because of the peculiar situation with the system config.

    I'll take another look when I'm next doing dev work on Windows, where I think it will be easier for me to revisit the situation I first reported.

  5. added this to the Backlog milestone on Jul 24, 2025
  6. added a commit that references this issue on Oct 20, 2026
    7f33b0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggit

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions