By default, Git completely ignores directories because it’s an intentional design choice. Since empty dirs don’t include any files or content, therefore they’re ignored. And sometimes, we might need to add an empty directory in a repo for some reason. There is a quick hack though which involves using a popular non-conventional (not being part of the Git standard) file named
Step 1. Create an empty directory and add the
mkdir _temp && touch _temp/.gitkeep
Step 2. Commit the file and push it to remote. For instance:
git add _temp/.gitkeep git commit -m "add empty _temp folder" git push origin main
To find more neat Git commands and hacks, browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.