Git add a folder with spaces in the name

Jonathan Yeong picture Jonathan Yeong · Dec 10, 2014 · Viewed 27.8k times · Source

Problem

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.

For example

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/.

Summary

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!

Answer

WinterChild picture WinterChild · Jul 14, 2016

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 :)