Git Tracks Files, Not Folders

Learn the trick to track empty folders in Git.

We'll cover the following

Git doesn’t track folders. This may bother us when we create empty folders as placeholders in a project—for example, an empty images folder at the beginning of a web project.

Add a hidden file

If we need to track folders, we usually add a hidden file there. Communities often use an empty .gitkeep file for this purpose, but it’s not a standard. We may pick any file name to commit the file and track the folder path.

For example, if we create a folder named images and call git status, we won’t see the newly created folder. But if we put a file in this folder, we see it. We can test this with the following commands in the terminal provided below:

$ mkdir images
$ git status
$ touch images/.gitkeep
$ git status

Here, we see the images file as an untracked file.

Get hands-on with 1200+ tech skills courses.