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

+1 vote
asked Nov 2, 2017 by Hitesh Garg (352 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, 2017 by Rahul Singh (543 points)  
selected Nov 4, 2017 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:


124 questions

41 answers


928 users

Most popular tags

java python python3 oracle database java-8 sql-server python2 oracle11g git oracle-12g command-line maven sql-server-2012 sql input array list fenitoina dilantin javaçš„ angular javascripts git-branch intellij-idea hashmap collection file-io io temovate clobetasol ampicillin principen daclatasvir daklinza vasotec enalapril nexium esomeprazole tadalafil tadlis sildenafil citrate pefomax xeloda capecitabina clobetasol temovate stemetil prochlorperazine methotrexate methotrexate sildenafilo y dapoxetina super kamagra norvasc amlodipine citalopram celexa amitriptylin saroten vitamin b12 methylcobalamin valaciclovir valtrex zudena udenafil sildenafil citrate vigour depakote divalproex retin-a tretinoine sildenafil citrate ip-max nizoral ketoconazol ciaton tadalafil norethisteronacetat aygestin indomethacin indocin tiova tiotropium bromid finasterida proscar lithium carbonate eskalith finasterida propecia levitra vardenafil vantin cefpodoxima loxitane loxapine rulide roxithromycine avodart dutasterid tecnomax sildenafil citrate methylcobalamin vitamin b12 permethrin acticin etinilestradiol norgestrel ovral pk-merz amantadin cycrin medroxyprogesterone serophene clomiphene spironolactone aldactone mesalazin pentasa zebeta bisoprolol cytodrox hydroxyurea ampicillin ampicillin pletal cilostazol paracetamol panadol pepcid famotidina meclizine hydrochloride antivert donaton tadalafil sdf dsfs sdgfgsdg mac null-pointer-exception constructor oracle-12c terminal hibernate-5 hibernate git-merge es6 programming git-amend git-commit java-stream git-remote multithreading access-modifiers nested-classes
Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.