From f1b9d505526676dd71d0e35c2a2730941436a8ee Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Thu, 16 Jul 2026 17:31:15 +0300 Subject: [PATCH] Bonsai: default new Git repos to a main branch IfcGit.init_repo() called git.Repo.init() with no branch argument, so newly initialised repositories inherited whatever the machine's global init.defaultBranch was set to, falling back to git's legacy "master" default when that config was absent. Check the global init.defaultBranch setting first, and only pass initial_branch="main" when it is unset, so existing user configuration is still respected. Addresses the "default branch should be main" item from issue #3096. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/tool/ifcgit.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/tool/ifcgit.py b/src/bonsai/bonsai/tool/ifcgit.py index 4ceb6fb5e5..f4ec8dd1db 100644 --- a/src/bonsai/bonsai/tool/ifcgit.py +++ b/src/bonsai/bonsai/tool/ifcgit.py @@ -61,7 +61,14 @@ class IfcGit(bonsai.core.tool.IfcGit): @classmethod def init_repo(cls, path_dir: str) -> None: - IfcGitRepo.repo = git.Repo.init(path_dir) + kwargs = {} + try: + git.Git().config("--global", "--get", "init.defaultBranch") + except git.exc.GitCommandError: + # global init.defaultBranch isn't configured, so git would otherwise + # fall back to its legacy "master" default; use "main" instead + kwargs["initial_branch"] = "main" + IfcGitRepo.repo = git.Repo.init(path_dir, **kwargs) cls.config_info_attributes(IfcGitRepo.repo) @classmethod