Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get git to ignore all contents of a directory?

Tags:

git

I have a git directory which contains the a whole bunch of files and then has a directory called 'sessions'. 'sessions' contains cookie information for my web.py program.

I need the folder 'sessions' to remain in the git repository because without the folder the program does not function correctly. I don't need the actual contents of folder being stored in the git directory.

So the question is:

How can I get git to ignore the contents of a folder but not the folder itself?

like image 548
Tabitha Avatar asked Jan 27 '09 04:01

Tabitha


People also ask

What is the command to ignore Git?

There is no explicit git ignore command; instead, the . gitignore file must be edited and committed by hand when you have new files that you wish to ignore. The . gitignore files hold patterns that are matched against file names in your repository to determine whether or not they should be ignored.


2 Answers

Add a sessions/.gitignore file with

* !.gitignore 

The second line tells git not to ignore the .gitignore file, so the folder is not empty but everything else is ignored.

like image 68
Mathias V Avatar answered Sep 30 '22 04:09

Mathias V


If I'm remembering correctly, you can do this by creating a .gitignore file in the sessions folder with [^.]* as its contents.

like image 28
ceejayoz Avatar answered Sep 30 '22 03:09

ceejayoz