Branch Guard Before Implementation

Rule

Before any serious implementation, verify branch state: git status --short --branch must not report HEAD (no branch) (detached) and git branch --show-current must not return main. If either condition holds, abort and create or switch to a topic branch first. Do not claim work is complete while commits are local-only — completion requires a pushed branch or open PR unless the user explicitly asked not to publish.

Why

Two failure modes get caught by this guard. First: an agent that accidentally starts work on main and commits directly bypasses branch protection on the local side, then pushes either successfully (compromising the PR contract) or unsuccessfully (leaving the work stranded in local commits no one else can see). Second: an agent that finishes work and reports “done” while the commits are still local — the user thinks the work shipped but CI never ran, no PR was opened, no review happened. The guard is a one-second check that prevents both.

Applies To

In-platform coworkers, external coding agents, and humans working in the repo. Symmetric. Applies before serious implementation and before any “I’m done” claim.

How To Apply

The pre-implementation check: git branch --show-current. If it returns main, run git checkout -b <prefix>/<topic> before continuing. If it returns nothing (detached), figure out what branch you should be on and switch. The pre-completion check: have you pushed? If git status shows commits ahead of origin, you haven’t shared the work yet. The user expecting a PR cannot see local-only commits; saying “done” while in that state is wrong.

Decision Dimensions

Examples

Sources

(Rendered from the sources: frontmatter by WikiSourceCitations.)