Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for using git in website deployments

Tags:

git

I'm doing an internship for a period of five months at a company at the moment and I'm going to change the way that developers access files, aka git instead of plain ftp access. Everything with git is going fine untill now, I'm a bit familiar with the usage after a month of using it.

This is what I have in mind right now:

enter image description here

We are using beanstalk as a repo hoster, which comes with a deployment function that works realy easy, so that part is covered. The part that gets me thinking is branch-wise. I was thinking of making a branch called 'Live' and just 'master'. master will be deployed to the development website (top right on the picture) and the live branch will be deployed to the live website. Also, the live website deployment will be manual, but the master should be automaticly, so far, no problem.

When I think of a scenario of small changes to the live website, there is where it gets complicated. Let's say I need to change the padding of some random div, I do not want to deploy the latest build with a half implemented api to the live website, I only want to deploy the small change, is this possible some way?

The way I see it now is do the fix on two places, first pull the master branch and fix it, then do the same for the live branch. But this will get harder with bigger changes.

Also, since we use Wordpress for pretty much everything, most of the data will be stored in the database. This is realy nice because we just need to clone the live database every now and then and we're done. But when image uploading comes into play, stuff gets pretty ugly. The repo will have a few of the images in it (because we didnt use git since the very beginning they are in there from a full copy) and others that will be added later will just sit there in the ftp dir, pretending they are in the repo!

Would it be better to not include folders like cache and media in git at all, or only some, or just update it once in a while?

Those are pretty much my two biggest problem of them all.

tl;dr: How to commit small changes to a branch that is out of date without doing it twice (also for master). And what is normal usage of cache/media files in a git repo?

like image 547
Gideon Avatar asked Mar 05 '13 14:03

Gideon


1 Answers

I suggest you read up on git flow.

It solves this exact problem.

Basically you have the following branches:

  • master: What you call "Live"
  • develop: That's where development happens
  • feature: For bigger changes during development that are too interrupting to be performed on the normal develop branch
  • hotfix: That's the one for your small fixes.

The important part is which branch is based on what other branch:

  • develop will branch off of master.
  • feature will branch off of develop.
  • hotfix will branch off of master.

The changes of develop will be merged into master after they have been fully tested. A merge into master means: This is a release, all testing is finished.

That means that master always contains the current live state, so branching a hotfix off of master is guaranteed to not introduce any other changes made by development.

This is just a short write up on the branching model that git flow implements. I suggest you read it in full. It also has some nice graphics :)

like image 62
Daniel Hilgarth Avatar answered Sep 24 '22 08:09

Daniel Hilgarth