gitdirectoryignoregitignore

How can I Git ignore subfolders / subdirectories?


I have a lot of projects in my .NET solution. I would like to exclude all "bin/Debug" and "bin/Release" folders (and their contents), but still include the "bin" folder itself and any DLL files contained therein.

.gitignore with "bin/" ignores "Debug" and "Release" folders, but also any DLL files contained in the "bin" folder.

bin/Debug or bin/Release in the .gitignore file does not exclude the directories unless I fully qualify the ignore pattern as Solution/Project/bin/Debug—which I don't want to do as I will need to include this full pattern for each project in my solution, as well as add it for any new projects added.

How can I do it?


Solution

  • Use wildcards:

    Solution/*/bin/Debug
    Solution/*/bin/Release
    

    With version 1.8.2 of Git, you can also use the ** wildcard to match any level of subdirectories:

    **/bin/Debug/
    **/bin/Release/