From 3c79b4501420263096cd168def51d64ef76aae42 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Tue, 30 Dec 2025 14:22:40 +0800 Subject: [PATCH] Fix #5112: Filter out branches with empty names in git config When .git/config contains a [branch ""] section with an empty name, lazygit was unable to display branches or remotes. This fix filters out any branches with empty names when loading branch configuration, preventing the issue. The fix is minimal and focused on the specific issue: empty branch names are now excluded from the returned branch map in the ConfigCommands.Branches() method. Signed-off-by: majiayu000 <1835304752@qq.com> --- pkg/commands/git_commands/config.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/config.go b/pkg/commands/git_commands/config.go index a9fd4e14772..7ccff45ae9d 100644 --- a/pkg/commands/git_commands/config.go +++ b/pkg/commands/git_commands/config.go @@ -78,7 +78,16 @@ func (self *ConfigCommands) Branches() (map[string]*config.Branch, error) { return nil, err } - return conf.Branches, nil + // Filter out branches with empty names to handle edge cases where + // .git/config has [branch ""] sections + filteredBranches := make(map[string]*config.Branch) + for name, branch := range conf.Branches { + if name != "" { + filteredBranches[name] = branch + } + } + + return filteredBranches, nil } func (self *ConfigCommands) GetGitFlowPrefixes() string {