I have a simple blog application written in Python, using Django. I use Git to version-control this website. The main content of the site is a blog. The blog entries are stored in a SQLite database (which is not version-controlled, but is backed up regularly); some entries contain images and other media (like PDFs).
I currently store this ‘blog media’ in the repository, alongside other media (such as external JavaScript code, and images used for layout purposes — all nicely organized, of course). It occurred to me, however, that this isn’t really a good strategy, for a few reasons:
- Whenever I post a new blog entry that contains an image or a link to a PDF, I have to add the image to the repo and then copy a new version to the production server — which seems like a lot of work just to add an image. It’d be easier just to upload the image to the server (and make a local backup, of course).
- Since this media is content rather than code, it doesn’t seem necessary to store it alongside the code (and related style media) itself.
- The repo contains a lot of binary files, which increase the overall size of the repo; and more importantly,
- I never really edit these images, so why keep them under version-control?
So I’m considering removing these files from the repo, and just copying them to a directory on the server outside of the directory containing the Python code, templates, style sheets, etc., for the website.
However, I wondered: Is there a ‘best practice’ for dealing with content images and other media in a website’s repo, as opposed to images, etc., that are actually used as part of the site’s layout and functionality?
Edit
To elaborate, I see a difference between keeping the code for the website in the repo, and also keeping the content of the site in the repo — I feel that perhaps the content should be stored separately from the code that actually provides the functionality of the site (especially since the content may change more frequently, and I don’t see a need to create new commits for ‘stuff’ that isn’t necessary for the functioning of the site itself).
You are completely correct on two points.
You have come to the correct conclusion that the ‘content images’ are just that and have no business in your code’s Version Control.
Backup your content images along with your database. You do not want to blur the lines between the two unless you want your ‘code’ to be just your own blog site.
What if you wanted to start a completely different blog. Or your friends all wanted one.You wouldn’t be giving them a copy of your database with all your content. Nor would it be any use for them to have a copy with all your content images.