How can I add an empty directory (that contains no files) to a Git repository?
Maybe adding an empty directory seems like it would be the path of least resistance because you have scripts that expect that directory to exist (maybe because it is a target for generated binaries). Another approach would be to modify your scripts to create the directory as needed.
mkdir --parents .generated/bin ## create a folder for storing generated binaries
mv myprogram1 myprogram2 .generated/bin ## populate the directory as needed
In this example, you might check in a (broken) symbolic link to the directory so that you can access it without the ".generated" prefix (but this is optional).
ln -sf .generated/bin bin
git add bin
When you want to clean up your source tree you can just:
rm -rf .generated ## this should be in a "clean" script or in a makefile
If you take the oft-suggested approach of checking in an almost-empty folder, you have the minor complexity of deleting the contents without also deleting the ".gitignore" file.
You can ignore all of your generated files by adding the following to your root .gitignore:
.generated