Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git add all subdirectories

I'm having trouble adding a folder and all of it's subdirectories to my git repository. I realized this is a very popular question after doing some googling and I've tried each suggestion with no luck, specifically the suggestion from the man page on git-add. I even tried git add -A with no success. For simplicity sake, say I initialized my git repository as Dir1. Then I have the following directory structure of files.

Dir1/file1-1.txt Dir1/file1-2.txt Dir1/Dir2/file2-1.txt Dir1/Dir2/Dir3/file3-1.txt 

My real files have subdirectories that span 5-6 levels deep, so is there a git command to add all the files in each subdirectory to my repository? Right now, when I do the suggestion from the man page git add Dir1/\* I can see Dir2 in my repo, but it shows up as a green folder and I can't open it, which leads me to believe that all the files/folders in Dir2 did not get added. Any help would be greatly appreciated. I'm a new git user (less than a week of using it), so try and keep your instructions at a beginner's level.

like image 402
Josh Bradley Avatar asked Jan 31 '13 07:01

Josh Bradley


People also ask

Can you git add a whole directory?

Add All Files using Git Add. 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.

Is git add recursive?

The git add command will recursively add all the files in that particular directory.

How do you git add all?

To add and commit files to a Git repositoryEnter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.


2 Answers

Do,

git add . 

while in the root of the repository. It will add everything. If you do git add *, it will only add the files * points to. The single dot refers to the directory.

If your directory or file wasn't added to git index/repo after the above command, remember to check if it's marked as ignored by git in .gitignore file.

like image 68
Kalle Pokki Avatar answered Oct 14 '22 05:10

Kalle Pokki


Simple solution:

git rm --cached directory git add directory 
like image 39
Shashwat Gupta Avatar answered Oct 14 '22 05:10

Shashwat Gupta