I’ve really come to love my version control setup that I’ve been using heavily over the last several months, and I wanted to share it. It’s really quite simple and it has saved me a lot of headaches. I had been using a central, cloud-based storage method for uploading my working code (Google Docs, Dropbox, etc.) so that I had access to the code wherever I was and whatever device I happened to be using.
Here is the problem, though. For example, I’m coding on my desktop and am about ready to head out the door to continue coding at the coffee shop. So I zip up all of my files, upload them to the cloud, then download them to my notebook. That’s not too horrible of a process, but how do I fit version control into this scenario? My first try ended in more steps and more headaches as I could never keep the working copies and repositories in sync.
Then I heard of Dropbox’s synced folder feature. This was the answer. Now I don’t even move or package my files at all! I simply commit them to the repository. Here’s how it works.
First, I setup Dropbox with the synced folder feature enabled on all of the devices that I intend to use.
Any files I drop into any of these folders will automatically replicate to the other folders. Next, I setup a Subversion repository in the Dropbox folder of any one of the devices, which of course then replicates.
So here I am, back on the desktop. I checkout the latest version of the project code from the repository in the Dropbox folder, make my changes, then commit those changes back to the repository. The repository is now updated on all devices.
On over to my laptop, let’s say I’ve already been working on the code from there as well. I perform a Subversion update on my working copy of the project, which grabs all of the changes I made on my desktop, then merges them into my local working copy. As usual, I make changes and commit back to the repository, and so on and so on.
One final note. It’s good to have that repository backed up, so on one of my devices, I have Amazon’s Jungle Disk installed, which backs up my Dropbox folder every night.
So as you can see, once everything is set up, I simply hop on a device of my choice, update my working copy, make changes then commit back to the repository. Done. No headaches.
TortoiseSVN, a subversion client for Windows, is used for version control. It is open source and highly regarded in the programming community. You can use it for just about any kind of project, but the most popular is for controlling source code. You can find out more about it at http://tortoisesvn.tigris.org/.
Using TortoiseSVN is incredibly easy, but people first starting out may find that the myriad of options can be overwhelming. TortoiseSVN does have a simple interface, but you will quickly realize that there are several methods available to carry out similar tasks. After piecing together bits of the official documentation and unofficial videos, I finally settled on a method that works for me.
Even more bewildering, especially if you are new to this process, is how to place an existing project under version control. I will specifically describe how I handle that, and will describe how I set up a repository and working folder to maintain my files on a daily basis.
Step One – Create the Repository
The repository is where your master files are kept — where files will be checked in and out of. Simply create a normal Windows folder, anywhere. We will call ours “My Project Repo”. Then right-click the folder for the context menu and select TortoiseSVN | Create repository here. You will then get a confirmation that the repository was successfully created. From now on, you will never treat this folder as a normal Windows folder.
Step Two – Import the files
Since we have an existing project, we will now import our project files into the repository. You will want to choose your highest level folder in your project hierarchy to import. We will be placing a Visual Studio project (called CampaignMonitorTest) under version control, so we will want to choose the folder in the main Visual Studio/Projects folder. (I realize that there is a VS plugin for TortoiseSVN, but I wanted to stay away from that for now).
To import the project folder into the repository, open the repository browser by right-clicking the My Project Repo folder and selecting TortoiseSVN | Repo-browser. A window will display the contents of your repository. Right now it is empty.
Right-click in the file area of the repo browser window and select TortoiseSVN | Add folder.
In the next window, navigate to your project folder and select OK. Enter a log message in the pop-up window, such as “initial import of project folder”. TortoiseSVN will then import your entire project. You can navigate your folder structure in the browser, just as you would in Windows explorer.
Step Three – Checkout a Working Copy
Your SVN folder is currently holding version 1 of your project, but your Visual Studio project folder has no connection with version control whatsoever. To remedy that, let’s first delete the Visual Studio project files from the project folder (this is the actual project folder in your Visual Studio hierarchy. If this seems scary at first, make a backup of your project files first). Now, checkout a working copy of your repository to the Visual Studio/Projects/CampaignMonitorTest folder by first right-clicking the top-level folder in the repo browser and selecting Checkout.
In the next window, navigate to your Visual Studio/Projects/CampaignMonitorTest folder for the Checkout directory.
After clicking OK, TortoiseSVN will checkout a working copy of your project. You will see that you are currently at revision 1.
If you look at your working copy, inside the Visual Studio hierarchy, you will see your project folder with an icon overlay, indicating that your project is currently under version control, and is up-to-date.
Step Four – Ignore Unnecessary Files
There are a few things inside our project folder though that we don’t necessarily want versioned. For example, the files inside the obj folder are automatically created upon project compilation, so we don’t need to include those. In TortoiseSVN, we simply add that folder to the ignore list by right-clicking the folder and selecting TortoiseSVN | Delete and add to ignore list. You will then see a new icon overlay, indicating that the folder is marked for deletion (not from your file system, mind you, but from version control).
Step Five – Commit Files
Up in the Visual Studio/Projects folder, you will notice the CampaignMonitorTest folder is indicating that files within it have been modified and not yet committed back to the repository (this will normally be caused by your modifications to the code, but right now it is because we marked a folder for deletion).
Right-click the folder and select SVN Commit… Enter a log message and click OK. You will then see that your files are at revision 2.
You will now notice in your Visual Studio/Projects folder that all of your versioned files display the overlay indicating that they are up-to-date. You will also notice that the obj folder has a new overlay, indicating that it is currently being ignored by version control, as you requested.