I have an images folder for a slider in my project that uses the database to create and serve the images. The problem I'm having is each time I push to the server I overwrite the files on the server and there a no images to display, how do I not delete the images on the server when pushing local project. I tried doing gitignore but that's no what I want because it will exclude the folder from being uploaded so I would have no path to upload to. I have also tried using git update-index --assume-unchanged public/data1/images/ and that doesn't seem to work either.
Asked
Active
Viewed 64 times
1 Answers
1
One workaround would be to make sure the http configuration of your web server will serve images (url: http://yourServer/images/...) from a folder which is completely outside the tree where the bare git repo is checked out.
That way, on the production server, the git repo images
folder is ignored.

VonC
- 1,262,500
- 529
- 4,410
- 5,250
-
I'm totally new to git and I don't understand what your saying could leave me some more explanantion and code please – ONYX Feb 22 '16 at 21:20
-
@ONYX first, you should push to a bare repo that is then checked out somewhere. http://stackoverflow.com/a/15930178/6309. Or you can push directly to a non-bare repo: http://stackoverflow.com/a/28381311/6309 – VonC Feb 22 '16 at 21:23
-
@ONYX Second, the rest is not git-related, but web-server-related: you need to configure your web-server in order for it to serve images coming from a folder which is *not* part of the checked out git repo. – VonC Feb 22 '16 at 21:23
-
@ONYX It depends on your actual web server. Here is an example for NGiNX: https://www.nginx.com/resources/admin-guide/serving-static-content/ – VonC Feb 22 '16 at 21:26
-
@ONYX the main idea remains: no matter what you are pushing in the image folder of your git repo, it does not matter, because the web server will serve images coming from another completely different folder. No overwrite! – VonC Feb 22 '16 at 21:27
-
I really don't get this you need to explain the steps for me to get this - All I've been doing is adding and committing and pushing to the server that's all I know what to do, like I said I'm new to git. I have a local repo no repo on github or bitbucket - just pushing local to server at the moment – ONYX Feb 22 '16 at 21:43
-
@ONYX As I said, the actual solution depends on the web server which runs on your local server. Is it Apache? NGiNX? – VonC Feb 22 '16 at 21:44
-
are you trying to make my repo on the server in a folder like /myproject/ and then have another folder on the server inside httpdocs /images/ – ONYX Feb 22 '16 at 21:45
-
I'm using fortrabbit so I don't actually no – ONYX Feb 22 '16 at 21:46
-
@ONYX that is the idea: modify the web server config in order, just for the image folder, to be served from another folder: that way, you don't overwrite anything when you are pushing your git repo. – VonC Feb 22 '16 at 21:46
-
OK the web server config I don't know where that is! I'm using the website interface for set settings like ENV Vars etc and there is no webconfig. – ONYX Feb 22 '16 at 21:50
-
@ONYX then that is a good question to ask to fortrabbit support: how to configure the server in order to serve images from another folder than the default one? – VonC Feb 22 '16 at 22:04