the .gitkeep trick: how to make git track empty folders
You build the thing, you push the project to GitHub, but when your friend clones it and tries to build, it doesn’t work because a folder you needed is missing. Does that sound familiar? 😅
This happened to me too. But here’s the catch: it’s not on GitHub, it’s on git. Git doesn’t track empty folders.
So when you were making your commits, git didn’t actually capture that empty folder in your file structure.
But the fix is a little trick. You just need to drop an empty file inside that folder and then, boom, magically git understands it should keep that folder around.
Because developers like conventions, we all agreed on a name for this empty file: it’s called .gitkeep.
That way git is happy, it has a file to track, and so the folder comes along. Keep in mind that .gitkeep is not an official git feature, but it’s a convention most of us use. And hey, if it works, it works, you know? 🤷
Want to see more git tricks like this? I covered this one in more depth here: Creating empty folders in git with .gitkeep
Follow along for more git tips like this!