How to add an empty directory in git?

git does not allow you to add a blank folder in your git repository but you can add an empty directory (technically it’s not empty) by adding a gitignore or gitkeep file inside the empty directory as shown below.

Note: You do not have to use gitignore file, this can be any file even an empty file.


Create a new local git repository:

Create your 1st git commit:

Create an empty directory:

Check git status:

Observe, git has not detected any change in your working tree. Now let us create a gitingore file inside this empty directory that excludes itself

Create a gitignore file inside the empty folder that exclude itself:

Check git status:

Add the blank folder to git:

Leave a Reply