Is 'feature/$thing' a legal branch name? Ask this.
Validates whether a string is a legal Git ref name, by exactly the rules Git itself enforces. The honest answer to 'can I name a branch this?' without trial-and-error.
A small filter: feed it a candidate name, get exit 0 if Git would accept it, non-zero otherwise. Refs must have at least one '/' (e.g. refs/heads/foo) unless --allow-onelevel; the rules ban '..', '~', '^', ':', '?', '*', '[', backslashes, leading/trailing dots, '@{', and more.
git check-ref-format [--normalize] [--allow-onelevel] [--refspec-pattern] <refname>
git check-ref-format --branch <branchname-shorthand>
git check-ref-format --print <refname>
Returns exit 0 if the name is valid, non-zero otherwise. With --print
or --normalize, also writes a cleaned form to stdout. With --branch,
expands @{-N}, @{upstream}, etc., to the actual branch name.| Flag | What it does |
|---|---|
--allow-onelevel | Accept single-component names like 'foo' (no '/'). Without it, refs must look like 'refs/heads/foo' or at least 'heads/foo'. |
--refspec-pattern | Allow exactly one '' as a wildcard component, for refspecs like 'refs/heads/'. Otherwise '*' is rejected. |
--normalize | Strip leading slashes and collapse runs of '/'; print the cleaned name on stdout. Combine with --print's behavior implicitly. |
--print | Print a normalized version of a valid ref; equivalent to --normalize for printing purposes. |
--branch <name> | Expand a branch shorthand: '@{-1}' becomes the previously checked-out branch, '@{u}' the upstream, etc. Returns the resolved name on stdout. |
git checkout - output).git check-ref-format --allow-onelevel feature/login || echo invalidprev=$(git check-ref-format --branch @{-1})git check-ref-format --normalize 'refs//heads///foo'git check-ref-format --refspec-pattern 'refs/heads/*'git rev-parse --abbrev-ref output when you want the @{-N} or @{u} forms — it's purpose-built and cheaper.Hit each option, then Check answers. Score is recorded; Next is always open.