user1934428
user1934428

Reputation: 22291

How to write .gitignore, so that a directory is put in git, but not its contents

Say I have a directory .../parent, containing various files and subdirectories. One of this subdirectories is /parent/slave

I would like to have all the files in .../parent/slave git-ignored, but not the directory slave itself - i.e., someone cloning the git repository, would always find an empty slave directory.

What do I have to put into .gitignore to achieve this?

Upvotes: 0

Views: 294

Answers (1)

Jared Davis
Jared Davis

Reputation: 569

I think you can just about what you want by adding a .gitignore to the ../parent/slave directory with contents such as:

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

If that doesn't do what you're after, the other answers here may be helpful:

How do I add an empty directory to a Git repository?

Upvotes: 4

Related Questions