Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git add a whole folder

Tags:

git

github

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

like image 261
sledge_909 Avatar asked Jun 01 '17 11:06

sledge_909


People also ask

Can you git add a folder?

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.


2 Answers

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

like image 104
Gauthier Avatar answered Sep 21 '22 15:09

Gauthier


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 .
like image 36
FallAndLearn Avatar answered Sep 19 '22 15:09

FallAndLearn