Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a blank directory to a Git repository?

How can I add a blank directory (that contains no files) to a Git repository?

like image 756
Laurie Young Avatar asked Sep 22 '08 16:09

Laurie Young


People also ask

How do I add a directory to Git?

Add only one file, or one part of the changed file: git add README.md. Commit the first set of changes: git commit -m "update the README to include links to contributing guide" Add another file, or another part of the changed file: git add CONTRIBUTING.md.

Can you have an empty directory in git?

Hi there, Yes, indeed, by design, you can not commit empty directories, containing no files, to a Git repository.


1 Answers

Another way to make a directory stay (almost) empty (in the repository) is to create a .gitignore file inside that directory that contains these four lines:

# Ignore everything in this directory * # Except this file !.gitignore 

Then you don't have to get the order right the way that you have to do in m104's solution.

This also gives the benefit that files in that directory won't show up as "untracked" when you do a git status.

Making @GreenAsJade's comment persistent:

I think it's worth noting that this solution does precisely what the question asked for, but is not perhaps what many people looking at this question will have been looking for. This solution guarantees that the directory remains empty. It says "I truly never want files checked in here". As opposed to "I don't have any files to check in here, yet, but I need the directory here, files may be coming later".

like image 85
Jamie Flournoy Avatar answered Oct 06 '22 00:10

Jamie Flournoy