I came across a file named .gitkeep whille studying Shadcn/ui source code and I wanted to share what it is about in this article.
We look at the following:
What is .gitkeep file?
Where do you find .gitkeep in shadcn/ui codebase?
What is .gitkeep file?
Git only tracks files not directories, so when you create empty directories and push, these empty directories are not pushed to your repository unless you have some file in it.
To solve this problem, you could simple add a dummy file in your directories and push it and have the latest directory structure reflected on your Github repo or you could simple just add a .gitkeep file and leave this file blank.
There is no special meaning to this .gitkeep file than to just sync your local directory structure with your Github repository.
Further reading:
Now that we understand what a .gitkeep is, let’s find out where you could find this file in Shadcn/ui codebase.
Where do you find .gitkeep in shadcn/ui codebase?
There are few directories in which I found this .gitkeep file.
pages/api
In this pages/api, it has this below shown structure
pages
In the pages folder, you will find the below structure
registry
Although this directory is automatically generated using scripts in the shadcn/ui codebase, it still has this .gitkeep
Let’s go back to the original definition of .gitkeep. When there’s an empty directory, to sync the folder structure with your Github repo, you create this file .gitkeep but after the initial push with empty dirs would you still need to have this .gitkeep folder? I personally don’t think its needed to have .gitkeep file even though your directory is no longer empty.
About me:
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com
My Github — https://github.com/ramu-narasinga
My website — https://ramunarasinga.com
My Youtube channel — https://www.youtube.com/@thinkthroo
Learning platform — https://thinkthroo.com
Codebase Architecture — https://app.thinkthroo.com/architecture
Best practices — https://app.thinkthroo.com/best-practices
Production-grade projects — https://app.thinkthroo.com/production-grade-projects
Top comments (1)
Yes, these files are obviously unnecessary artefacts if the folder is populated with actual code/data files already. Sometimes folks just don't know what they're for and leave them. No big deal. But to me, the less clutter the better.