8

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?

3
  • isn't this question better suited for programmers.se? Commented Mar 5, 2013 at 15:07
  • I have no clue, never been there. Should take a look I guess. :) Commented Mar 5, 2013 at 15:16
  • Here's the best practice: don't use Git as a deployment tool. Use — guess what — specialized deployment tools. Commented Aug 15, 2015 at 13:48

1 Answer 1

17

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 :)

Sign up to request clarification or add additional context in comments.

13 Comments

This looks realy awesome! I'm going to look into this tonight. The only thing it does not fix is the files that are added with the upload funtion of Wordpress.
@Gideon: I didn't really understand that part :) Why not just git add them?
You can't '@' me, because you are commenting on my answer. I will be notified anyway :) I don't know beanstalk and all the other software involved, so I might be suggesting nonsense here. But some ideas nevertheless: git clone your repository on the server that receives the files in a way that the files will automatically be in the correct subdirectory. Add a cronjob to periodically git add ., git commit, git push all new files in this directory.
You can refer to this blog post (scroll down to "Part 2") on how to create a cronjob that does git work. It does a pull but you should be able to adjust that easily to a "add, commit, push".
@Gideon: If you are always only working on one feature, yes. A small example: I am the only developer for a certain software. Still, I am developing on develop and on two feature branches. On develop I check in small fixes, for example: Typo in a comment, variable rename, small bug fix etc. On one feature branch I develop a new feature whose development takes some time. On another feature branch I perform some medium scale refactoring. Both feature branches are regularly rebased onto develop via git flow feature rebase <featurename>.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.