DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > How to Add a Blank Directory to Your Git Repository

How to Add a Blank Directory to Your Git Repository

Let's look at how to add a blank directory to your git repository.

Johnny Simpson user avatar by
Johnny Simpson
CORE ·
May. 26, 22 · Web Dev Zone · Tutorial
Like (1)
Save
Tweet
6.24K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Plain Text
 
- 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:

Plain Text
 
*
*/
!.gitignore

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:

Shell
 
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.

Git Blank (solution) Directory Repository (version control)

Published at DZone with permission of Johnny Simpson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Are Microservices?
  • No-Code/Low-Code Use Cases in the Enterprise
  • DZone's Article Submission Guidelines
  • When Writing Code Isn't Enough: Citizen Development and the Developer Experience

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo