DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on

.gitkeep file in Shadcn/ui source code

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:

  1. What is .gitkeep file?

  2. 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:

  1. https://www.freecodecamp.org/news/what-is-gitkeep/

  2. https://adamj.eu/tech/2023/09/18/git-dont-create-gitkeep/

  3. https://gist.github.com/jlollis/54d3b3a7ed12776ac9f0d4bc13e63ed9

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

Image description

pages

In the pages folder, you will find the below structure

Image description

registry

Although this directory is automatically generated using scripts in the shadcn/ui codebase, it still has this .gitkeep

Image description

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

References:

  1. https://github.com/shadcn-ui/ui/blob/main/apps/www/pages/api/.gitkeep

  2. https://github.com/shadcn-ui/ui/blob/main/apps/www/pages/.gitkeep

  3. https://github.com/shadcn-ui/ui/blob/main/apps/www/__registry__/.gitkeep

  4. https://www.freecodecamp.org/news/what-is-gitkeep/

  5. https://adamj.eu/tech/2023/09/18/git-dont-create-gitkeep/

  6. https://gist.github.com/jlollis/54d3b3a7ed12776ac9f0d4bc13e63ed9

Top comments (1)

Collapse
 
fyodorio profile image
Fyodor

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.