Reputation: 6073
So I noticed that since git names folders based on the branch names in the file system (in the refs folder specifically i.e. remotes) this can cause issues since the allowed characters in the folder names are OS dependent.
For example you can create a branch on MAC OS like:
feature/my_special_"Splash Screen"_feature
If I fetch this on Windows, it's gonna fail with a message like:
Fetch failed: fatal: Unable to create 'C:/AndroidStudioProjects/MyProject/.git/refs/remotes/origin/feature/my_special_"Splash Screen"_feature.lock': Invalid argument
Since the file name contains aposthropes which are not allowed on Windows, while allowed on MAC OS.
When you try to create the same branch on windows, git will simply remove the aposthropes.
Does anyone know any official documentation on this? Also, do we need to rename this branch or is there a workaround?
Upvotes: 2
Views: 274
Reputation: 1324657
One non-official policy is mentioned in "Legal Git branch names", referencing this thread:
A Git branch name can not:
- Have a path component that begins with "."
- Have a double dot ".."
- Have an ASCII control character, "~", "^", ":" or SP, anywhere
- End with a "/"
- End with ".lock"
- Contain a "\" (backslash)
That patch (for a better error message on invalid branch name) was not implemented, and it does not include double-quotes at the time.
But still, it is a good idea to avoid any special character in branch names.
This comment in refs.c remains the closest of an official policy:
/*
* Try to read one refname component from the front of refname.
* Return the length of the component found, or -1 if the component is
* not legal. It is legal if it is something reasonable to have under
* ".git/refs/"; We do not like it if:
*
* - any path component of it begins with ".", or
* - it has double dots "..", or
* - it has ASCII control characters, or
* - it has ":", "?", "[", "\", "^", "~", SP, or TAB anywhere, or
* - it has "*" anywhere unless REFNAME_REFSPEC_PATTERN is set, or
* - it ends with a "/", or
* - it ends with ".lock", or
* - it contains a "@{" portion
*/
Upvotes: 3