What is .gitkeep in Git? Plus an example? |Video upload date:  · Duration: PT4M53S  · Language: EN

Quick explanation of .gitkeep why empty folders are ignored by Git and a practical example to keep directories tracked

Git has many virtues but keeping empty folders on the radar is not one of them. By default Git tracks files not folders so when you need an empty directory to exist in your repo you create a tiny placeholder file and teach Git to care. The community favorite for this little exercise is called .gitkeep which is just a convention not a magic spell.

Why you might want an empty folder

Some apps expect folders to exist for logs temporary uploads or generated assets. If a folder is missing your code may crash in ways that are delightful to debug at 3 a m. Adding a placeholder file ensures the structure is preserved when someone clones the repo and runs the code.

What .gitkeep actually is

The file named .gitkeep does nothing special to Git. It is a plain file that you add to an otherwise empty folder so Git will track that folder. The name signals intent to humans not to Git. Treat it as a tiny seatbelt for your repository structure.

Quick example commands

mkdir logs
touch logs/.gitkeep
git add logs/.gitkeep
git commit -m 'Add logs folder with .gitkeep'

Alternatives that are slightly more talkative

  • README in the folder. This explains why the folder exists and is great for future you or teammates who enjoy context.
  • .gitignore trick Use a pattern that ignores everything but lets one file in. This is handy when you want to ignore generated content but keep the folder itself tracked.

Example .gitignore for a folder you want present but empty

logs/*
!logs/.gitkeep

Common mistakes to avoid

  • Thinking .gitkeep does anything special to Git. It does not.
  • Committing the placeholder to the wrong branch and then wondering why it is missing. Branches are real and they do not share memory.
  • Having a global ignore rule that hides your tiny file. If that happens add a local negate pattern like in the example above.

When to prefer README and when to prefer .gitkeep

If the folder benefits from a short explanation prefer a README file. If you just want the smallest possible tracked artifact use .gitkeep. Both are valid repo management tools and both fit into git best practices depending on what you value more clarity or minimalism.

Final tip for version control survival

Use whatever makes the repository easier for humans to understand and for the code to run. That could be a tiny file called .gitkeep a README or a clever .gitignore rule. Just do not summon mysterious folder not found errors at runtime and then blame Git for having standards.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.