Search code examples
gitgitignore

exclude a subfolder that can appear multiple times


I have the following source tree:

main_folder
main_folder/data
main_folder/subfolder1
main_folder/subfolder1/data
main_folder/subfolder1/subfolder
main_folder/subfolder1/subfolder/data
................
................

What's the proper .gitignore syntax, to exclude the data subfolder, wherever it appears in the source tree?


Solution

  • in a .gitignore file you're able to ignore files in multiple different ways. You could exclude files by setting them piece for piece like the example below:

    /main_folder/data
    /main_folder/subfolder_1/data
    ...
    ...
    

    But you're also able to select al the subfolders in a folder by using the asterix symbol like the example below:

    /main_folder/*
    /main_folder/subfolder_1/*
    

    in your case you should use the following to exclude all folders with the name data. Example:

    data/
    

    A simulair question like yours you can find here

    hope this helps!