Git checkout / switch branch
branch = name from this message (trimmed). If missing, ask once and stop.
Steps
git status --short. If the working tree is dirty andgit switchwould fail, report and stop — commit/stash/discard only if the user says so in this message.git fetch --allwhen network is allowed (skip and say so if forbidden).- Resolve and switch:
- Local
branchexists →git switch branch - Only on remote →
git switch branchif Git tracks it unambiguously; elsegit switch -c branch --track origin/branch - Neither local nor
origin/branch→ authorization gate (next section)
- Local
- Done when: HEAD is on
branch, or you stopped at a hard stop / unanswered create gate.
Authorization gate (missing branch)
- State that neither local nor
origin/<branch>was found. - Ask whether to create local
branchfrom current HEAD (or from a base the user named). - Create only on a clear yes (
yes/proceed/create it). Otherwise stop. - On confirm:
git switch -c branch(orgit switch -c branch <base>if they named a base).
Guardrails
- No branch delete, force checkout of unrelated SHAs, or inventing names.