I have the following folder structure:
/foo/
/foo/test.txt
/foo/.gitkeep
/foo/bar/test.txt
/foo/bar/.gitkeep
/foo/bar/baz/test.txt
/foo/bar/baz/.gitkeep
Now I want to exclude all files in the folder "foo" and all files in its subfolders (and subsubfolders), except all the .gitkeeps (so that the folder structure is kept). This should also work for more than 3 levels of subfolders.
The following gitignore-rules work:
/foo/**
!/foo/**/
!/foo/**/.gitkeep
Can somebody explain, why this works? Is there a cleaner way of doing this?