Worktree setup fails when repo has no main branch (fatal: invalid reference: main). Should prompt for base branch.
What version of the Codex App are you using (From “About Codex” dialog)?
Version 26.217.1959 (669)
What subscription do you have?
Plus
What platform is your computer?
Darwin 25.2.0 arm64 arm
What issue are you seeing?
When initializing worktrees, Codex assumes a main branch exists and calls git worktree add against main. In repos where the default branch is not main (for example only production and staging), worktree creation fails immediately with:
fatal: invalid reference: main
git worktree add failed: fatal: invalid reference: main
This blocks worktree usage for repos that do not use main.
<img width="800" height="630" alt="Image" src="https://github.com/user-attachments/assets/7eda77ec-891e-4122-891f-15f04aac224d" />
What steps can reproduce the bug?
- Create or use a git repo that does not have a main branch (only production and staging, for example).
- Configure Codex to use worktrees (or run the workflow that triggers worktree initialization).
- Attempt to initialize/create the worktree.
Result: Worktree setup fails with fatal: invalid reference: main.
What is the expected behavior?
If main does not exist, Codex should not hard-fail. It should either:
- Use the repository’s actual default branch (origin HEAD), or
- Prompt the user to choose the base branch to create the worktree from (for example production or staging), and remember that choice per repo.
Additional information
Rationale: Many repos intentionally do not have main. A robust fix is to resolve base branch via origin/HEAD (or equivalent) rather than assuming main, with an interactive fallback prompt when default branch cannot be determined.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗