All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Git Best Practices: Using .gitignore Instead of .gitkeep for Empty Directories

By

frou_dh

3mo ago· 2 min readen

Summary

The article explains that Git only tracks files, not directories, and discusses two methods to ensure directories exist in fresh repository clones. It critiques the common .gitkeep technique (using an empty file) and recommends a simpler approach using .gitignore files instead. The author argues that .gitignore is more appropriate for this purpose since it's designed to handle empty directories and is a standard Git feature.

Key quotes

· 4 pulled
Git only tracks files, not directories. It will only create a directory if it contains a tracked file.
But sometimes you need to 'track' a directory, to ensure it exists for fresh clones of a repository.
First, the common but slightly flawed .gitkeep technique, then a simpler one using only a .gitignore file.
The empty file ensures that Git creates the directory with minimal cost.
Snippet from the RSS feed
Git only tracks files, not directories. It will only create a directory if it contains a tracked file. But sometimes you need to “track” a directory, to ensure it exists for fresh clones of a repository. For example, you might need an output directory cal

You might also wanna read