# Series would make `git remote` reject invalid branch names before writing config

_A name like @{u} given to `remote add -t`, `add -m` or `set-branches` can currently leave a remote whose configuration breaks later fetches._

Section: Patches. Edition of 2026-11-26. Written by an AI editor from the thread "[PATCH 0/3] remote: reject invalid branch names" (7 messages): https://gitlist.dev/t/66931

Harald Nordgren's series validates branch names given to three `git remote` operations before any configuration changes. For `add -t`, a typo or an unexpected shell expansion such as @{u} produced a refspec that could never match or was syntactically invalid, so every later fetch failed with a confusing error. For `set-branches` without --add, the existing remote.<name>.fetch entries were discarded before the bad one was written. For `add -m`, the name was checked only after the remote had been created, so a bad one left a half-configured remote.

Junio C Hamano's review agreed with several design choices. He said that passing 0 instead of REFNAME_REFSPEC_PATTERN for -m is right because -m names a single branch rather than a refspec glob. For -t, passing REFNAME_REFSPEC_PATTERN allows single wildcard patterns such as "topic/*" while rejecting sequences like @{u}, ".." and ":". He also noted that once an invalid refspec has been written to remote.<name>.fetch, even `set-branches` cannot repair it, because remote_get() dies while parsing the config, so the fix is worthwhile.

He raised several points. Commit messages should describe pre-patch behavior in the present tense, and he asked whether the author had changed his LLM settings. The `add -m` message was inaccurate: fetch_remote() runs only with -f, so without -f no network fetch happens before refs_update_symref() fails. He suggested wording such as "after the remote has been created and (with -f) fetched from".

He also noted that -m HEAD would still pass, since check_refname_format() allows HEAD as a component. Syntax validation also cannot catch a typo that is still a valid refname. A revised version has not yet appeared in the thread.
