1

I have my .gitignore file like so

.gitignore

/data*
/node_modules/*
/bower_components/*

I want to have the directories pushed and pulled but not the contents of the directory. As it is above, the directories are ignored entirely. Is this possible?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

2 Answers2

3

You can put a .gitignore file in each directory you want to track without contents, and have its contents (the .gitignore's file, that is) be *, which would ignore all files in that directory. git add those .gitignore files and commit them. The result should be that the directories are tracked (because of the tracked .gitignore files in them), but any files in those directories will be ignored.

Tonio
  • 1,516
  • 1
  • 15
  • 25
2

Git tracks content, not files. Sort-of as a result of this, it doesn't track directories either. You can kinda achieve this effect by putting a 'dummy' file in a directory, and tracking that file, but doing this and not tracking anything else in that directory can be annoying (if all your files don't have similar file names, ie: all end in .py)

Also: How to commit a directory into a git repository? answers the same question phrased differently.

Community
  • 1
  • 1
ThisGuy
  • 2,661
  • 2
  • 18
  • 18