I tried:
git branch "MyProj/bin/ ignored"
and received:
fatal: 'MyProj/bin/ ignored' is not a valid branch name.
The git-branch man page points to the git-check-ref-format man page to get the actual rules for a valid branch name.
Sure enough, the reason for the above fatal error appears to be the inclusion of a space character.
Any idea why, in this day and age, spaces are still excluded from a branch name (I would have expected it in ancient CVS, for example, but Git?)
What could be valid technical reasons for that?
In Git, the git branch branch-name command is used to create a new branch called branch-name . Branches should be named something that describes the purpose of the branch. Note that branch names can't contain whitespace: new-feature and new_feature are valid branch names, but new feature is not.
Naming rules for refname: Git imposes the following rules on how references are named: They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence . lock .
Use Hyphen or Slash as Separators My opinion is that hyphens make the name more comfortable to read, so it's a suitable separator in branch names. You can use slashes, hyphens, and underscores.
I do not know if you are going to find a pure, technical reason down at the bottom of this. However, I can offer that spaces tend to throw wrenches in all sorts of *nix utilities and filename processing, so it may have been to avoid accidentally doing anything wrong further down the line. After all, a git branch boils down to a file in the repo and this avoids dealing with spaces in that file's name (specifically, a branch is a file in .git/refs/heads/, as mentioned in the comment).
Mostly I would guess the reason is philosophical, and meant to keep things simple. Branch names are human-readable names that have no real reason to be complicated (and require typing two extra chars each time haha, to invoke the ghost of the sysadmin who has aliased every command to an indecipherable three letter combination). Otherwise known as the "why cd is not chdir" argument.
old thread, but hey..
on a mac i use alt + space. it's gonna add an invisible character that will do the trick for you. mind: it's not a 'space', it's an invisible character. visually the same thing, but effectively not the same. 100% likely going to confuse the hell out of anyone else and definitely going to bring chaos everywhere, but hey, for the kicks.. why not? xD
git checkout -b US24024 Automated Tests - Profile A Switched to a new branch 'US24024 Automated Tests - Profile A'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With