AI Hints
Home›Git & GitHub Tutorial›Everyday Gotchas
Git & GitHub · Lesson 116 of 144

Empty Folders

Why Git ignores them.

⏱ 2 min read▶ Video at 2:07:23🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Try this. Make an empty folder, and run git status. Git says nothing. Git tracks files, not folders. A folder only exists in Git because files are inside it.

Empty Folders
From the video: Empty Folders
  • An empty folder
  • git status says nothing
  • Git tracks files, not folders

The empty folder trick

We make an empty folder called images. Status shows nothing. The common trick is to put an empty placeholder file inside, called dot git keep. Now status shows the folder, and we can commit it.

git
mkdir images
git status --short
touch images/.gitkeep
git status --short
?? images/
git add images
git commit -m "Add images folder"
[main 50315ec] Add images folder
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 images/.gitkeep

About .gitkeep

.gitkeep isn't special to Git. It's just an empty file, with a name everyone recognises. Some people use a readme file instead, explaining what the folder is for. Either way, the folder now has a file, so Git tracks it.

.gitkeepjust a convention
Empty fileany name works
Or a READMEexplain the folder
Resultthe folder is tracked

Summary

Git tracks files, not folders. Put a dot git keep file in a folder to keep it. Next, renaming a file when only the capital letters change.

Key takeaways
  • Git ignores empty folders
  • touch folder/.gitkeep
  • Commit it
Next up: Changing Capital Letters — case-only renames