Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for ignoring files within a folder with GIT

Tags:

git

gitignore

I'm just looking for some advice on the best way to manage the following situation with git.

my project has a folder called "photos" that users can upload images to.

I have a version of the project running locally and I am adding images to this folder for testing purposes.

When I push to the live server I want the "photos" folder to get pushed but not the images within it. Also when users add images to the "photos" folder on the live server I want GIT to ignore them.

I know I need to use Git Ignore but I'm unsure what the best way to do this is.

Should I just add "photos" to the git ignore file and then manually create the "photos" folder on the live server?

Thanks in advance.

like image 731
Daelan Avatar asked Jan 06 '11 20:01

Daelan


1 Answers

echo '*' > photos/.gitignore
git add -f photos/.gitignore

Git does not support empty directories, but standard practice for a directory is to create a .gitignore file inside it. The * entry causes git to ignore anything inside the directory (even the .gitignore file itself, hence the add -f to override that).

like image 95
Josh Lee Avatar answered Oct 08 '22 20:10

Josh Lee