gitignore - Exclusions for Ignore

11/21/2021, Sun
Categories: #git

Avoid Ignoring Folders that has Files Within them to Ignore

Supposedly, there is a need to ignore generated content within a folder called "temp":

# .gitignore

test/temp/*

You will want this behavior when you are creating a folder in your test suite where you want to have this folder when starting the test for storing the generated files, but do not want to keep the generated files around after the testing has completed.

However, this will totally ignore the folder from being tracked in git even though there is a ".gitkeep" file within "temp". The solution to this problem is to use an exclusion rule where you specify that the .gitkeep file should be kept around for tracking:

# .gitignore

test/temp/*
!test/temp/.gitkeep