I have a folder in Git with some files in it. Files are a part my Git repository. When running my project some work directories appear in this folder. Directories can have any name and any nesting level with multiple sub-directories. I want to ignore all possible sub-directories appearing in this folder but still keep all files (not directories) sitting in root of my folder.
I've tried patterns:
/
*/
/*
/*/
None of above gives desired result. How it can be accomplished?
Many answers explain how to ignore folders with specific names, for instance Git ignore sub folders. But there seem no explanation on how to ignore all sub-folders with wild cards.
gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder. You can also tell Git to ignore multiple files or folders using the same method.
A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .
Try this:
!folder/
folder/*
The first line excludes the top level from being ignored, and the second line ignores all subfolders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With