Git doesnt track directories

suggest change

Assume 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents