When I want to add something to the staging area I normally type git add < folder-name >. However, I can't add folders with spaces in the name. My git add
auto complete doesn't correctly escape the spaces.
I have a folder named: Folder A
I run the command git add F < tab-autocomplete >
which becomes git add Folder A/
. If I try and add this folder it will throw an error:
fatal: pathspec 'Folder' did not match any files
This is because the correct syntax should be git add Folder\ A/
.
I'm not sure how to fix this though and I can't find any resources with a permanent fix. This issue "How git deals with folder names with spaces" describes a fix. But it involves putting speech marks around the folder name which I don't really want to do. Is there a better solution?
I'm using git version 2.2.0 and zsh version 5.0.7. Thank you in advance!
Leading (before the filename) and trailing (after the filename) spaces in file or folder names also aren't allowed. If you're using Office 2010, you can't use "&" in file and folder names. These names aren't allowed for files or folders: . lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_, desktop.
The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.
GitHub does not allow you to add blank folders to your Git repository. A folder must contain a file before you can add it to a repository. If you want to create a new folder, create it first and then add a placeholder file into that folder. Then, add the new folder and file to your Git repo.
Surround the folder or file with a space in it with quotes! On Mac and Linux, you can add single quotes, but on Windows you'll have to use double quotes. …and everything worked as expected! This works for all the git commands: so add and diff , for instance, are included.
The solution is to wrap the folder name inside ' and ' (single quotes).
In your example, try the following:
git add 'Folder A'
I hope this helps :)
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