Empty files and folders

Github often ignores empty files, but in a package I need a few empty files to write session data to, and that file cannot be filled. Also, Github does not create the folder if a file is empty, which results in an incomplete clone.

What is the best solution for this?

This shouldn’t be the case, Git only ignores empty folders (because it only tracks files).

To workaround to force Git to track empty folders it to create an empty file called .gitignore, so the folder is no longer empty — I can assure you that Git will track the empty .gitignore file!

The name .gitignore is arbitrary, it could be called anything, but the well established convention is to name it .gitignore, so that everyone immediately understands that it’s just a placeholder to force Git to track a file (and hence, it can be safely deleted once there are other files in the directory tree).

If Git is ignoring an empty file (i.e. a file with 0 Kb size) than the reason must be another, most likely due to rules defined in a .gitignore file somewhere along the directory tree structure (or even in your global ignore options).

To check which files are being ignored in your repository, type:

git ls-files --others -i --exclude-standard

Use that command in the repository root to show all ignored files, or in the folder where you’re experiencing the problem you mentioned, to see if the empty file shows up as being ignored — in that case, your problem is in the .gitignore rules.


Thank you, that makes sense.