How to ignore all subfolders in a folder using .gitignore

I have a folder in Git with some files in it. Files are part of my Git repository. When my project starts, some working directories appear in this folder. Directories can have any name and any nesting level with several subdirectories. I want to ignore all possible subdirectories appearing in this folder, but still save all the files (not directories) located in the root of my folder.

I tried templates:

/
*/
/*
/*/

None of the above gives the desired result. How can I do that?

Many answers explain how to ignore folders with specific names, for example Git ignore subfolders . But there seems to be no explanation on how to ignore all wild card subfolders.

+4
source share
2 answers

Try the following:

!folder/
folder/*

The first line excludes ignoring the top level, and the second line ignores all subfolders.

+3
source

It is pretty simple. Create .gitignorein the folder with:

*/*

those. ignore all files that are in any folder of the current folder.

+4
source

Source: https://habr.com/ru/post/1664432/


All Articles