209 words
1 minutes
Codex: The specified git ref main does not exist

Recently, I encountered the error “Codex: The specified git ref main does not exist” while using Codex, which puzzled me for a while. I’m sharing this as a record for future reference.

Problem: “Codex: The specified git ref main does not exist”#

When integrating GitHub with Codex and trying to execute, the error “Branch does not exist” is displayed.
This likely occurs because Codex is designed to select the main branch by default, so it happens when older repositories only have a master branch (I missed taking a screenshot of the error message).

Codex Error Example

Solution 1: Select Branch from Prompt Input UI#

The simplest method is to select the target branch from the dropdown at the bottom of the prompt UI.
Once you select master from the list, it will remain selected as master for subsequent executions.

Solution 2: Change Branch Name to main#

For a fundamental solution, change the branch name from master to main on the repository side. Main has become the standard in many recent tools. You can make this change with a single command:

git branch -m master main

Summary#

When you start using Codex, you may find some inconveniences in the details, but you can use it comfortably by reviewing the settings.
If you’re having trouble with the same error, first check your branch settings.

Codex: The specified git ref main does not exist
https://naonao-na.com/en/posts/codex-error-branch/
Author
[object Object]
Published at
2025-07-07