Search code examples
gitgitignore

Git ignore subfolders but not the files in a folder


I've been looking around and just could not find the same scenario that I have. I have:

--public
      |--img
           |--logo (folder)
           |--post_image (folder)
           |--banner.jpg
           |--icon.ico
           |--image1.jpg
           |-........etc

I need to ignore the logo and post_image folders, but I want to keep every file that is inside img folder. How would I go about it?

Right now I have **/public/img but I feel is not the right approach!


Solution

  • I found this to be simpler (at least in the case there are many subfolders):

    public/img/*/
    

    This will exclude all subfolders in public/img/, but will not exclude the files in this folder.