21

I'm new to git and I am trying to git add my whole working directory but I receive the error message:

fatal: pathspec 'folder' did not match any files.

I'm in the working dir when I do this command, what am I doing wrong? Also, is it good practice to commit the whole folder instead of file by file? Thank you

Chiller
  • 9,520
  • 2
  • 28
  • 38
sledge_909
  • 457
  • 1
  • 5
  • 9

5 Answers5

34

My guess is that you are trying to add folder while you already are in folder.

$ cd my_folder
$ git init
$ git add my_folder # this is not going to work

Instead, add everything in the folder, rather than the folder itself:

$ cd my_folder
$ git init
$ git add .

To your other question, adding whole folders is fine, but only relevant when adding sub-folders. Again, you can't git add the folder that is your repository (my_folder above).

$ cd my_folder
$ ls
my_subfolder  other_things
$ git add my_subfolder # this is fine

The usual way to add everything in your working tree to your repo is git add ..

Gauthier
  • 40,309
  • 11
  • 63
  • 97
16

You need to first check if you have added that folder in .gitignore file.

If not, then just do this.

git add --all 

or

git add .
FallAndLearn
  • 4,035
  • 1
  • 18
  • 24
3

If the folder contains space you need to enclose the name with quotation marks:

git add "New Folder/"
Mendi Barel
  • 3,350
  • 1
  • 23
  • 24
1

I think your folder is not under git version control, or you ignored it.
try to run git add -A to add your folder

1

you must type the folder's name between quotation marks.

here is the pseudo-code:

git add 'folder name'
  • 1
    That's definitely not normally required. Maybe your folder includes a space in it? Or has special characters? In any case, quotes are unrelated to this being a folder. – ChrisGPT was on strike Jul 05 '22 at 20:58