919 - 926 - 9847

How I use Subversion for Web Development

Take this with a grain of salt.  I've read over various how-to's, and although this isn't 100% consistent with some of that, it's worked well for me.


I'm not going to document creating a server, and presuppose you've already done this.  I'll show an example using subClipse and an example using Tortoise SVN client.  The other "gotcha" is you'll need two separate copies of your codebase, or you'll need to "switch" your working copy.  I prefer to have a separate codebase, so that's what you'll see here.  I'll also show you a great little SVN hook, svn2web.

First, some client agnostic instructions:

  • Create a new repo, or create a new project within an existing one.  We'll call ours "MySite"
  • Create a branches folder, and a trunk folder within this new project.  Fairly standard stuff here.
  • In the branches folder, create a PROD_100 folder. 

This is we part ways with "the norm".  We're going to be using the PROD folder to hold our current production site code.  In the end, we'll use svn2web to push changes to our production server.  TRUNK is going to hold all of our current (and on going) development.  We'll be pushing TRUNK to our development server.
Toirtoise SVN

  • Check out your new TRUNK, I put mine in c:\cf_dev\projects\mysite_dev.  After creating the folder to hold your project, right click and choose SVN Checkout… and browse to the SVN server where you created the trunk.
  • Check out your new PROD, I put mine in c:\cf_dev\projects\mysite_prod.  After creating the folder to hold your project, right click and choose SVN Checkout… and browse to the SVN server where you created the PROD_100.
  • Create a new text/html/whatever file in c:\cf_dev\projects\mysite_dev.  I made a test.cfm file.
  • Commit this file.  Right click the file, SVN Commit.  Follow through the prompts, give a comment if you wish.  You now have a file sitting in your TRUNK folder.
  • IMPORTANT: Before you can get this change into PROD, you will need to SVN Update on the c:\cf_dev\projects\mysite_prod folder.  Right click this folder, and choose SVN Update.  This will need to be done EVERY SINGLE TIME!
  • Right click the c:\cf_dev\projects\mysite_prod folder, and choose TortoiseSVN-> Merge…  Choose to merge a range of revisions.  On the next screen, point the URL at where your current TRUNK folder is located.  Then, use the show log to choose your revision ranges, and click next.  Leave the defaults, and choose merge.
  •  Provided you have no conflicts, and at this point you shouldn't as it's a new file, it's time to commit the changes.  You won't be able to merge any other files into this working copy until you commit the current changes!  So, go ahead and right click the c:\cf_dev\projects\mysite_prod\test.cfm file and SVN Commit.
  • Congrats!  You've now merged a change into your production environment!

Eclipse/Subclipse

  • I tend create a new eclipse project for production and development.  So go ahead and create a project for production and development, c:\cf_dev\projects\mysite_dev and c:\cf_dev\projects\mysite_prod.
  • Right click the project, and select Team-> Share Project.  Choose SVN, and the URL to your repository.  Follow through the prompts.  Do this for each project, TRUNK and PROD_100
  • Create a new file in the mysite_dev project. 
  • Right-click the project, and team -> Commit… your changes up
  • On your PROD project, right click and Team-> Update to Head.
  • On your PROD project, right click and Team -> Merge.  Choose to Merge a range of revisions.  Chose the URL to your SVN TRUNK.  After clicking next, you get a nice table view of the available ranges of revisions, along with the comments.  When it finishes, it'll display a dialog of changes.
  • IMPORTANT: You MUST update the PROD project with Team-> Update to head… every single time you wish to do a merge.  You also MUST commit pending changes before you can do any further merges.
  • Commit the merged changes with Team-> Commit.
  • Congrats!  You've now merged a change into your production environment!

Now, the caveats. 

The concept the of merging is thus, at least according to the docs.  You're supposed to create a branch to work on from trunk.  After you're done working with this branch, ideally you would then re-integrate with trunk.  We will not do this.  Ever. 

The idea that I go by is trunk is for all current and future dev, and these branches (PROD_100, PROD_200) match major revisions in my deployment.  I realize that "tags" are typically used for releases, however, that makes are more sense to me when you're talking about Java/C++/insert language here.  For web development, I just don't see this as viable.  Add to that the inclusion of the svn2web hooks that I use, it'd be a tremendous pain to create a hook for every single tag that I'd add.  There's times I make 20-50 commits a week across my various client base.

Next post I'll detail svn2web, but for now, this is how I (and my team) leverage SVN to publish content to our websites.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Jim Priest's Gravatar Interesting - reading up on svn2web now :)

How do you handle managing any config/code changes that need to occur between dev/prod? ie DSN, framework configs, etc.
# Posted By Jim Priest | 9/11/11 5:38 PM
Matthew Williams's Gravatar That sir, is worth more than just a comment. I'll write up a post on that in the 24 hours. ;)
# Posted By Matthew Williams | 9/11/11 7:20 PM