DEV Community

n350071🇯🇵
n350071🇯🇵

Posted on • Edited on

6 1

[git] Keep empty directory by .gitkeep

🤔 Situation

The repository is like this. The notes directory is empty. How can I keep the empty directory?

$ tree
.
├── Gemfile
├── Gemfile.lock
├── README.md
├── deleted.enex
├── notes             # <- The empty directory
├── parse.rb
└── parse_to_notable.rb

1 directory, 6 files
Enter fullscreen mode Exit fullscreen mode

👍 Solution

put an empty file at the directory. .gitkeep is popularly used.

$ touch notes/.gitkeep
$ ls -A notes/
.gitkeep
Enter fullscreen mode Exit fullscreen mode

like this

🔗 Parent Note

Top comments (5)

Collapse
 
eldercb profile image
Claudio Bertoli

Any file will work, because any file will make the folder not empty: I believe it's better practice to add a README.md file in the folder explaining the purpose of the folder.
Otherwise future developers might find a folder sometimes with not an intuitive name and wonder what it's for: it might even no longer be used, but with not explanation of its purpose a developer would need to dig into the code to understand that.

Collapse
 
pavelloz profile image
Paweł Kowalski

I think .keep works too ;)

Collapse
 
n350071 profile image
n350071🇯🇵

Thank you, it works too!

Collapse
 
jingxue profile image
Jing Xue

It's probably worth noting that any file name would work. .gitkeep is just a popular choice for this placeholder file.

Collapse
 
n350071 profile image
n350071🇯🇵

Thank you, my understanding was wrong. I've rewritten it.

Image of Bright Data

Feed Your Models Real-Time Data – Enhance your AI with up-to-the-minute data.

Utilize our live data feeds for dynamic model training, ensuring your AI systems are always ahead.

Access Real-Time Data

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay