Adding a file to Git Repository recursively. first, we need to create a deep nesting folder structure within a Git repository.
We know that Git adds all the files and directory to the staging area before doing commit, but what if you have subdirectory or files..?, the answer is yes, Git will add all the subdirectory or files to the staging area, we call this process as adding files recursively to Git Repository.
The Git Add command takes a path name for either a file or a directory. if it is a directory then the add command adds all the files in that directory recursively.
Now Let us understand this process through a demo as shown below:
pwdcommand to make sure that you are on your project folder.
lsyou can see there is starter-web-1/ folder, so this is our git repository. Now cd into it, it will be directed to a starter-web-1 folder and now give
git status, Git returns a message that it's on the master branch and your working directory is clean.
mkdir -p level1/level2/level3/level5, Thus do an
lsyou can see your first level folder directory.
pwdto see your path.
notepad++ level1-file.txt.so the default editor page will open, copy some dummy text from Ipsum.co and paste it here then save and exit.
lsyou can see level1-file.txt and level2 directory.
cd level2directory and
notepad++ level2-file.txt, copy some dummy text and paste it into the editor page, save and exist.
ls, you can see level2-file.txt and level3 directory.move to the level3 directory
cd level3and pwd.
notepad++ level3-file.txtand add some dummy text into that and save then exit.
lsyou will see level3-file.txt and level5 directory.
rm -rf level5.
Now go back to your root directory by using command
cd ../../.. . you returned to your starter-web-1/ folder and do an
ls, you will see a level1 folder in that. Do,
git status you can see only a first level directory as the untracked file.
However, am not able to see all the files recursively but I can add the files recursively to Git repository.
So to do that am going to use parameter
git add . It will add all the files recursively from this point forward. If I do
git status again it will show you all the new files as shown in the below image.
git commitpress enter, editor page will occur here, enter your commit message adding several files recursively and save then exit.