How to track empty directories with Git

If you’ve ever tried to track an empty directory with Git, you might have noticed the message “nothing to commit, working tree clean” after running git status. That’s because Git doesn’t track folders — it tracks files. Running git add <dir> will add only the files inside <dir>. If <dir> is empty, running git add <dir> does nothing.

So, back to the original question: what if we want to track an empty directory? Well, the short answer is you can’t. What you can do is add a dummy file to the directory. This placeholder file could be named anything, but the community-driven convention is to call it .gitkeep. By adding this file, you effectively preserve the directory structure, even though Git technically tracks the placeholder file and not the directory itself.

Another option is to add a README to the directory. If this directory is going to remain empty (maybe it gets populated at build time), the README is a great place to document that intention clearly.

If you plan to add real content to the directory eventually, I’d reach for .gitkeep instead of a README.


me
John-George Sample is a software engineer based in Pittsburgh, PA. He uses vim, btw.