Course Tonight

Course Tonight

Did You Know?

Docy turns out that context is a key part of learning.

Chapter 32: Empty directories in Git

Estimated reading: 1 minute 6 views

Section 32.1: Git doesn’t track directories When using Git, it’s important to note that Git doesn’t track empty directories. Assume you’ve initialized a project with the following directory structure:

/build
app.js

If you add everything and commit it:

git init
git add .
git commit -m "Initial commit"

Git will only track the file app.js and not the empty directory /build.

However, if you need to include an empty directory in your project, such as the build directory used as an output directory for a build step, you can use a convention of including a .gitkeep file inside the directory and let Git track that file.

/build
.gitkeep
app.js

To add the .gitkeep file, use the following commands:

git add build/.gitkeep
git commit -m "Keep the build directory around"

By adding the .gitkeep file, Git will now track the file build/.gitkeep, and as a result, the build directory will be available on checkout.

It’s important to note that this convention of using a .gitkeep file is not a built-in feature of Git but rather a common practice adopted by developers to ensure the preservation of empty directories in a project.

Leave a Comment

Share this Doc

Chapter 32: Empty directories in Git

Or copy link

CONTENTS