Git doesnt track directories
suggest changeAssume you’ve initialized a project with the following directory structure:
/build
app.js
Then you add everything so you’ve created so far and commit:
git init
git add .
git commit -m "Initial commit"
Git will only track the file app.js.
Assume you added a build step to your application and rely on the “build” directory to be there as the output directory (and you don’t want to make it a setup instruction every developer has to follow), a convention is to include a “.gitkeep” file inside the directory and let Git track that file.
/build
.gitkeep
app.js
Then add this new file:
git add build/.gitkeep
git commit -m "Keep the build directory around"
Git will now track the file build/.gitkeep file and therefore the build folder will be made available on checkout.
Again, this is just a convention and not a Git feature.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents