Prevent PR workflow pushes from targeting the tracked default branch

Open 💬 2 comments Opened Aug 20, 2026 by donatj

Summary

During a Codex desktop task to create a new PR branch, the agent created a local branch from origin/master and then ran:

git push --set-upstream origin codex/pinch-to-zoom

Because the local branch tracked origin/master, the operation updated the remote default branch instead of creating origin/codex/pinch-to-zoom. The push output made that explicit:

codex/pinch-to-zoom -> master

The agent then had to create and push a revert to restore master.

Expected behavior

When the task is to create a new PR, Codex should not push directly to the repository default branch unless the user explicitly authorizes it. Before a push, it should verify that the remote target differs from the default branch, or use an explicit matching refspec such as:

git push --set-upstream origin HEAD:refs/heads/codex/pinch-to-zoom

Impact

This can make unreviewed changes visible on a shared default branch and requires a follow-up revert. The agent should fail closed or ask for confirmation when a planned branch push resolves to master.

Environment

Codex desktop on macOS, GitHub remote, with a local feature branch initially created from origin/master.

View original on GitHub ↗

2 Comments

donatj · 8 days ago

Codex filed this issue itself. That's kind of interesting.

That said, I'm facing an issue where it pushes to master accidentally all the time. Multiple times a day. I'm having to set up branch protection on my individual projects just to stop it from pushing to master.

donatj · 8 days ago

And it did it again since it filed this...

I don't really exaggerate when I say it does this five times a day

<img width="1080" height="2400" alt="Image" src="https://github.com/user-attachments/assets/c9eb9ca4-9f83-4b34-8eb2-1c6464e5e837" />