How to add a Blank Directory to your Git Repository

Typically in Git, we wish to protect a listing to be used inside a repository, however preserve it empty of recordsdata. There are numerous explanation why you’d wish to do that, however maybe both the folder is used to retailer recordsdata the individual cloning the repository must create, or a script creates customized recordsdata to place into that folder.

If we wish to create a clean listing, we are able to do this simply, nevertheless it will not be pushed after we use git push to push to our distant. As such we have to do one thing barely totally different.

Making a clean listing in a Git Repository

The simplest method to do that is by making a .gitignore file inside the listing you wish to keep.

- index.html
- myRepository <-- Empty listing
- myCss
--- fashion.css
--- essential.css
Enter fullscreen mode

Exit fullscreen mode

We wish to push myRepository to our git repository. To try this, create a brand new file in myRepository referred to as .gitignore. In that file, put the next code:

Enter fullscreen mode

Exit fullscreen mode

This can ignore all recordsdata, folder and subdirectories, however embrace the .gitignore file itself. Meaning the file might be pushed, and we are able to preserve the listing whereas not retaining any of its contents.

Subsequent, simply push your git repository as you’d normally do by operating the next instructions:

git add .
git commit -m "Added .gitignore"
git push
Enter fullscreen mode

Exit fullscreen mode

Your listing will now persist in your repository, whereas the contents of the listing won’t.

Add a Comment

Your email address will not be published. Required fields are marked *