Why can't branch name contain char space?

I tried:

git branch "MyProj/bin/ ignored" 

and received:

 fatal: 'MyProj/bin/ ignored' is not a valid branch name. 

The git-branch page points to the git-check-ref-format man to get the actual rules for a valid branch name.

Of course, the cause of the aforementioned fatal error is the inclusion of a space character.

Any idea why spaces are still excluded from the branch name on this day and age (for example, I would expect it in ancient CVS, but Git?)

What could be justified technical reasons for this?

+43
git git-branch
Jul 08 2018-11-11T00:
source share
4 answers

I do not know if you will understand that you will find a pure technical reason below. However, I can suggest that spaces tend to throw wrenches into all sorts of * nix utilities and file name processing, so perhaps it was to avoid accidentally doing something wrong down the line. In the end, the git branch is reduced to a file in the repo, and this avoids spaces in this file name (in particular, the branch is a file in .git / refs / heads /, as indicated in the comment).

Basically, I would suggest that the reason is philosophical and designed to make everything simple. Branch names are human-readable names that have no real reason to be complex (and require you to type two extra characters each time haha ​​to call the ghost of the system administrator who smoothed each command into an illegible three-letter combination). Otherwise, this is called the argument "why cd is not chdir."

+47
Jul 08 2018-11-11T00:
source share

There is a possible workaround if you are disgusting enough. The Unicode set has many spatial characters. But only U + 0020 is a space that is prohibited. Take, for example, inextricable space, and you can have a branch name with spaces. The main problem is that your keyboard most likely does not have a key for this code point. I am using the following script to solve this problem:

 #!/bin/zsh git co -b "${@// / }" 

It simply replaces all spaces in the arguments with non-breaking spaces ...

+3
Jul 01 '15 at 13:57
source share

old thread but hey ..
on mac I use alt + space. he will add an invisible character that will do the trick for you. mind: this is not "space", it is an invisible character. visually the same, but actually not the same. 100% is probably going to confuse the hell out of anyone else and is definitely going to damage the chaos everywhere, but hey, for strikes .. why not? xD

git checkout -b US24024 Automated Tests - Profile A Switched to a new branch 'US24024 Automated Tests - Profile A'

+2
Dec 16 '16 at 16:40
source share

Not allowed as this will complicate the functionality of the git checkout command.

Example: Think that you currently have a branch, although you are currently in the master. If you run the command

(master): git checkout -b my fix

git does not know if you want to create a new branch named "my fix" or if you want to create a new branch named "my" which is related to your original "fix" and not to the "master".

Source: https://git-scm.com/docs/git-checkout (Git Documentation)

0
Jul 26 '16 at 17:32
source share



All Articles