Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Episode 6 - Ignoring Things: Exercise Ignoring Nested Files #634
The exercise prompt is
The construction of a .gitignore file that ignores one subdirectory has two solutions. One is trivial; the other is complex and, imo, requires intermediate to advanced knowledge of how git travels along directory paths.
The first and easiest solution is to specify directly all directories to ignore. e.g.
The second answer refers to the exclamation point operator, which has not yet been introduced. This answer allows git to ignore everything in a folder except one subfolder. The
For this example, assume
If the asterisk at the end of the second line,
It is similarly important to include both the third and fourth lines. The third line tells git it's okay to look at the directory
I have now tested this on MacOS and GitBash with the same results.
That said, I'm not sure if this exercise is appropriate for the lesson because of the intermediate/advanced solution. Perhaps the second solution should be listed as intermediate/advanced content, and a later exercise introduced, "Ignoring Nested Files, Part 2", with the explicit explanation and solution. But, IMO, the answer is confusing and somewhat incorrect because it refers to a solution to a different exercise that over simplifies the exclamation point operator, and doesn't address how it works with directories.