I have the following .gitignore:
# Ignore everything
/*
!/.gitignore
# Readd folders:
#!/mainfolder/ # this works!
!/mainfolder/subfolder/
!/mainfolder/subfolder/*
I want to ignore everything, but subfolder/
. Adding the line !/mainfolder/
works, so that /mainfolder is not ignored anymore. But I want to add only the things below subfolder/
and the second and third lines for subfolder/
do not work.
I have found several links online suggesting this is the correct way (e.g. this one). So what am I doing wrong?!
EDIT: I am using Git 2.17.1 from SourceTree on Windows 10. I have tested these results from the integrated MINGW64 bash.
You need to whitelist folders first, then files:
For any file still ignored, check why with:
That is similar to "Git - Unignore any folder located anywhere inside repository that recursively allows everything":