SVN Switch – Key to Success In Web Development

So lately I have been given some thought to how we use Subversion (SVN) in our web development, and features we don’t use nearly as often.

In web development, one big area where I don’t see us using a lot is branching, tagging, and merging. However, with our iPhone Apps, we use tagging and branching a lot. As I started to think why, one of the biggest things was the environment. Client development, especially with the iPhone, is double clicking on a project file for Xcode, and I’m ready to go. There is almost no hassle running trunk versus running a tag or branch. It is all the same.

Building against a website, however, is different. Your environment requires a lot more information and pieces. For me, I need to make changes to my host file (for custom domains), Apache/Nginx configuration, MySQL Connection information, etc. There is no file i “double click” and go. It is a pain anytime I need to change my local (or staging or even production) paths and settings.

This is where the svn switch command comes in handy, and is extremely important. It allows you to change your checked out working copy’s source (or url), while maintaining any local changes you may have made. You can tell the actual path, regardless of file or directory names, by doing an svn info command. The best way to understand is through examples.

Arg, should have made this a branch.

You’re working on a big change, such as completely rewriting your internal message system. Suddenly, your boss walks in saying “There is a bug we need you to fix and push live now!” It is a simple bug, but your trunk is only half way through a major change. What do you do?

  1. New Branch on Server – You need to make a new branch on the server based off the server’s version of trunk. It’s a simple copy function, while having it execute on the server:

    svn copy -m “Branching for new email system” http://svn.example.com/trunk/ http://svn.example.com/branches/new_email_system/

  2. Switch your trunk working copy to new branch – This allows you to keep all of your current changes locally, but switches you to the branch version:

    cd /path/to/trunk/
    svn switch http://svn.example.com/branches/new_email_system/

  3. Commit changes to branch – Commit your changes to the repository which will be applied to the branch:

    svn commit -m “changes to new message system.”

  4. Switch back to trunk. – Make sure you are still at your trunk. If you did an svn info, it would show the URL location at the branch. Execute the switch again:

    svn switch http://svn.example.com/trunk/

  5. Switch between trunk & branch as needed – When you need to work on the trunk, switch to the trunk. When you need to work on the branch, switch to the branch. The great thing is you won’t need to change any URLs in your configs in apache and such, it will just work.
  6. When your branch is ready, merge into trunk – Perform a merge since the starting of the branch to the last revision in the branch, applying it to the trunk:

    svn merge -r 100:125 path/to/branches/new_email_system path/to/trunk

  7. Test changes made by merge, then commit. – Test the changes locally, and when you are satisfied things went well, commit the merged changes to trunk: svn commit -m “new message”
  8. Continue Development – you are safe to proceed as usual.

Over the new few weeks I plan on posting more little tutorials and tricks of some more advanved SVN commands, and hopefully it can help some of my fellow team members. Let me know if you have any questions, or want to know how to do other things. But the bottom line is if you haven’t used the svn switch command, especially in web development, you are sorely missing out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close