d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

How to Add a Blank Directory to Your Git Repository

Sometimes in Git, we want to preserve a directory for use within a repository, but keep it empty of files. There are many reasons why you’d want to do this, but perhaps either the folder is used to store files the person cloning the repository needs to create, or a script creates custom files to put into that folder.

If we want to create a blank directory, we can do that easily, but it won’t be pushed when we use git push to push it to our remote. As such we need to do something slightly different.

Creating a Blank Directory in a Git Repository

The easiest way to do this is by creating a .gitignore file within the directory you want to maintain.

- index.html
- myRepository <-- Empty directory
- myCss
--- style.css
--- main.css

We want to push myRepository to our git repository. To do that, create a new file  myRepository called .gitignore. In that file, put the following code:

This will ignore all files, folders, and subdirectories, but include the .gitignore file itself. That means the file will be pushed, and we can keep the directory while not keeping any of its contents.

Next, just push your git repository as you would usually do by running the following commands:

git add .
git commit -m "Added .gitignore"
git push

Your directory will now persist in your repository, while the contents of the directory will not.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this