GetDefaultBranch() in internal/git/git.go falls back to hardcoded "master" instead of "main"
### Checklist
- [x] I'm using the latest version of the extension (Run `glab --version`)
- Extension version: glab 1.91.0 (266e9be)
- [x] Operating system and version: Linux 6.8.0-106-generic x86_64
- [x] Gitlab.com or self-managed instance? Both
- [x] I have performed `glab auth status` to check for authentication issues
- [x] Run the command in debug mode and attach any useful output
### Summary
`GetDefaultBranch()` in `internal/git/git.go` returns hardcoded `"master"` on error (lines 35 and 53). Most Git hosting platforms (including GitLab) have defaulted to `main` since 2021. This affects `mr create`, `mr for`, and `stack reorder` — all of which call `git.GetDefaultBranch()`.
Meanwhile, `internal/git/git_runner.go` already defines `DefaultBranchName = "main"` and its `StandardGitRunner.DefaultBranch()` method correctly falls back to `"main"`. The fix in MR !2286 addressed this for CI commands via `ciutils`, but `git.go`'s standalone functions were never updated.
### Environment
- OS: Linux 6.8.0-106-generic x86_64
- SHELL: /bin/zsh
- TERM: screen-256color
- GLAB: glab 1.91.0 (266e9be)
### Steps to reproduce
1. Have a GitLab project whose default branch is `main`
2. Create a feature branch and push a commit
3. Run `glab mr create` without specifying `--target-branch`
4. If `git remote show origin` fails or is slow to respond, glab falls back to `master`
### What is the current _bug_ behavior?
`glab mr create` targets `master` when `git remote show` fails, even though the project's default branch is `main`.
### What is the expected _correct_ behavior?
The fallback should be `"main"` (matching `DefaultBranchName` in `git_runner.go`), or ideally the function should query the GitLab API for the project's `default_branch` field instead of relying on `git remote show`.
### Relevant logs and/or screenshots
```go
// internal/git/git.go:27-36
func GetDefaultBranch(remote string) (string, error) {
getDefBranch := exec.Command("git", "remote", "show", remote)
getDefBranch.Env = os.Environ()
getDefBranch.Env = append(getDefBranch.Env, "LC_ALL=C")
output, err := run.PrepareCmd(getDefBranch).Output()
if err != nil {
return "master", err // <-- hardcoded "master"
}
return ParseDefaultBranch(output)
}
```
Callers:
- `internal/commands/mr/create/mr_create.go:914` — `br, _ := git.GetDefaultBranch(baseRepoRemote.Name)`
- `internal/commands/mr/for/mr_for.go:71` — `targetBranch, _ = git.GetDefaultBranch(repoRemote.Name)`
- `internal/commands/stack/reorder/stack_reorder.go:201` — `previousBranch, err = git.GetDefaultBranch(git.DefaultRemote)`
### Possible fixes
Replace the hardcoded `"master"` with `DefaultBranchName` (already defined as `"main"` in `git_runner.go:17`). This is the minimal fix.
A more thorough fix would consolidate `git.go`'s `GetDefaultBranch()` and `git_runner.go`'s `StandardGitRunner.DefaultBranch()` into a single implementation, eliminating the duplication that caused this divergence.
> **Disclosure:** This issue was drafted with assistance from Claude Code (Anthropic). The investigation, code audit, and reproduction were done interactively by a human developer.
issue