Git won't track empty directories (because at heart it only tracks files). Common advice is to add a '.gitkeep' file so the directory isn't empty and git will make the directory.

EVEN BETTER ADVICE: put a README in the directory explaining what the empty directory is for and what will eventually be there.

@nedbat, but if you put README in there it's no longer empty, and if it must be empty, then that is not going to work :-).
@mgorny It also won't be empty if you create a .gitkeep file in it.
@nedbat, sure. But the chance of ignoring "hidden" files is greater than chance of ignoring "visible" files.

@nedbat I usually have a .gitignore file with the following data:

*
!.gitignore

@lattera @nedbat I must admit to liking the readme idea more.

But I do wish subdir .gitignore was the default convention for templates and scaffolding than .keep files.

@nedbat But what do you do when all files from a folder are deleted in a certain commit. Leave a readme that this folder was once there for some kind of reason? Otherwise all people who once had pulled that commit end up with an empty folder that's not used for any thing...
@doekman @nedbat if you don't expect the folder to be used anymore, delete the folder as well. In other words, if you can't write a justification for that folders existence in the readme, it doesn't need to exist
@nedbat Another option that'd often (but maybe not always) be preferable: create the directory when it's needed, e.g. during build.

@airtower love this.

Versioning the empty dirs is a bandaid that addresses the symptom, not the root cause!!

@nedbat I think I like this better. It at least gives you the ability to explain purpose instead of just hacking git to follow it.
@nedbat @chrisjrn “This path is intentionally blank”
@nedbat this feels so obvious and I never thought of it, so thanks for the tip. To be fair to myself, I only resorted to using a .gitkeep once ever

@nedbat
One thing I started doing a few years ago is to add a .gitignore file that contains

!.gitignore
*

Instead of the wildcard, you can also list the specific things you want to ignore. Of course, a few comments about why you ignore what or why this exists helps as well 😇.

@nedbat
The gitignore serves then as both documentation and the replacement for .gitkeep
Better yet, make your project not rely on having an empty directory. If you need one, create it at runtime instead.
@nedbat I just did just yesterday while debugging, and then added an ASCII cow because why not
@nedbat lol i did that for work once and was told to use .gitkeep instead 🙄
@bunnyhero there are wrong people everywhere... :(
@nedbat @klappo Bitte notieren
@koralle @nedbat da verstecken sich unsere gut sortierten von Git ignorierten secrets drin  🤫
Und wen I first stepped over such a .gitkeep file, I thought is it something special, treated by git. I foubd is very well irritating (and still do). Thus a Readme file or a .gitignore (as suggested elsewhere in this conversion) is much easier to understand.
@nedbat
@nedbat the readme should have only five words. “This directory intentionally left empty”
@nedbat
That's been my habit, too. It makes a lot of sense.

@nedbat You can technically commit empty directories with some Git magic (https://github.com/dextercd/git-empty-directory/tree/main), but it's probably unwise.

A README is a lot more helpful. Good idea

GitHub - dextercd/git-empty-directory: demo git repo containing an empty directory

demo git repo containing an empty directory. Contribute to dextercd/git-empty-directory development by creating an account on GitHub.

GitHub
@nedbat oooh, so i have been doing it right? i stumbled upon that little hack. you can even make the file invisibleb, as long as you don't exclude all dotfiles.
@nedbat If that folder is accessible (e.g. it's part of a public facing site), a readme file might disclose something unwanted. Perhaps a .readme would be a better approach?
@nedbat Remove .DS_Store from your gitignore ... problem fixed 😎 In one go you can spread your Apple love 🙃