How can I add an empty directory to a Git repository?

+1 vote
23 views
asked Nov 2 by Hitesh Garg (251 points)  

I want to create an empty directory in a Github repository that contains no files. How can I do it?

1 Answer

+1 vote
answered Nov 4 by Rahul Singh (328 points)  
selected Nov 4 by Hitesh Garg
 
Best answer

As per the GIT you can not simply add a directory that has no file in it -

Currently the design of the git index (staging area) only permits
files to be listed, and nobody competent enough to make the change to
allow empty directories has cared enough about this situation to
remedy it.

Directories are added automatically when adding files inside them.
That is, directories never have to be added to the repository, and are
not tracked on their own.

You can say "git add

    " and it will add files in there. If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose; you can leave it empty, or fill in the names of files you expect to show up in the directory.

But there are some simple ways to make a directory stay empty (in the repository) is to create -

  1. Add an empty file named .gitkeep and then you can track this folder in the github. Although git does not provide any specific significance to this name it is simply a convention that has emerged over time. This file can be named anything.

  2. A .gitignore file inside that directory that contains below line:

    !.gitignore

41 questions

27 answers

3 comments

20 users

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...