Given the following lengthy folder structure in my repo and imagine all these folders has a sub-folder and sub-sub-folder, sub-sub-sub-folder, so on and so on (will only display the first two levels):
jim_folder >
name.txt
sub_jim_folder >
sub_name.txt
sub_sub_jim_folder >
sub_sub_name.txt
.....
tim_folder >
name.txt
sub_tim_folder >
sub_name.txt
sub_sub_tim_folder >
sub_sub_name.txt
......
amy_folder >
name.txt
sub_amy_folder >
sub_name.txt
sub_sub_amy_folder >
sub_sub_name.txt
.......
jerry_folder >
name.txt
........
Basically, I want to only
- track the
jim_folder
and all its sub-directories , files within sub-directories and all the sub-sub-directories and all the files within it , so on and so on. - And untrack other directories and their sub-directories and every single file or directories under them, i.e. untrack
amy_folder
,jerry_folder
,tim_folder
and every single files or directories within them.
Question :
From my understanding, there are 2 approaches to write .gitignore
in this situation:
- ignore everything in the repo except
jim_folder
and all its sub-directories and all its sub-sub directories and so on. - ignore explicitly
amy_folder
,jerry_folder
andtim_folder
by listing them out.
I would like to see the solution (code) for both approaches
because logically, the first approach should be adopted, but it seems like I would have a lot of lines to write if jim_folder
contains many sub, sub-sub, sub-sub-sub, .....directories.
On the other hand, I am not sure how to write the .gitignore file in the second method, do I also need to specify entire structures of those folders that I want to ignore in the .gitignore ? Because that would mean a lot and a lot of lines.
I am sure there is a best practice to this issue. I would like to hear them out.