Dropbox is a popular cloud-based storage and backup service. its success can be identified as maintaining a reliable service, and being available on every platform – including mobile ones.
In this article, I will explain how Dropbox can be used to manage the source code for small, personal projects. I’ll provide examples using both Git and Subversion.
So we all use Dropbox as a kind of virtual drive; a place to keep all the stuff that we want to have access to, from everywhere we go, and from any device. But what about our source code? Most developers will be familiar with the likes of Github, or Bitbucket for source management and revision control.
I’m not suggesting that Dropbox could replace either of those services of course. However, what about using it to look after small projects of your own? The kind of project where you still want to use version control, but where there is no need for the power of a service like Github?
Doesn’t Dropbox already have revision control?
Sort of. But it wouldn’t be suitable for version control. It’s more of a back up of each document/file you have stored. Also, you wouldn’t be able to commit and push to a repository if you relied just on that feature.
Getting started with Git
I’ll assume that you have a coding project that you want to use. If you haven’t already, initialise a Git repository while in the project folder from the console/command line:
Add the files in your project:
git add .
Then commit the files:
git commit -am 'initial commit'
Everything so far has been local to your computer. Next, change directory into your dropbox folder, and create a folder to hold your Git projects. Being adventurous, I called mine ‘git_projects’:
cd ~/Dropbox mkdir git_projects
Now you can switch back to the directory containing your actual code:
Next, we need to clone the project folder we just created in our Dropbox folder. We are going to clone this as a bare project so that we can push and pull to it. if you clone a project with a working tree already, it will cause complications with the push/pull process:
git clone --bare . ~/Dropbox/git_projects/sample_project.git
If you haven’t added any code to your project yet, you will receive a warning that you have cloned an empty project. But that’s fine, you can add some files shortly. Next, we need to add our Dropbox project as a remote alias so that we can push to it:
git remote add sample_project ~/Dropbox/git_projects/sample_project.git
Now you can add code and commit as normal. When you are ready to push to the Dropbox repository, you just do a:
git push sample_project master
To work with the code from another computer, you can clone the project:
git clone ~/Dropbox/git_projects/sample_project.git
Then work as normal, pushing back to the Dropbox repository when you have finished the updates.
Subversion works too
To achieve something similar with Subversion, the easiest way to get things working is to create the Dropbox directory first, convert it to a Subversion repository, and then checkout the trunk to add your code to.
cd ~/Dropbox mkdir subversion_projects cd subversion_projects
Now we can make a repository for our specific project:
svnadmin create sample_project
Then create the standard layout for a Subversion project. We’ll start with the trunk:
svn mkdir file://localhost/Users/you/Dropbox/subversion_projects/sample_project/trunk -m 'repo layout'
If you are on Windows, you will find this article useful, even though it’s a bit dated now. You can also look at using TortoiseSVN to make your life easier.
We can continue to make the default layout:
svn mkdir file://localhost/Users/you/Dropbox/subversion_projects/sample_project/branches -m 'repo layout' svn mkdir file://localhost/Users/you/Dropbox/subversion_projects/sample_project/tags -m 'repo layout'
Then, checkout the trunk:
svn checkout file://localhost/Users/you/Dropbox/subversion_projects/sample_project/trunk svn_project
Noe you can continue to add code as normal. Once you have finished your updates, add any new files with svn add, and then commit the changes:
svn commit -m 'latest updates'
Just as you can with the git example, you can simply checkout a working copy on another machine, add/edit code, and then commit back. Don’t forget to do an svn update when you use the original computer again.
Using Dropbox to act as a repository for Git and Subversion projects probably wouldn’t be a good idea for large teams. However, for your own projects, it’s a lot cheaper than using private repositories on Github for example. It also provides a way for you to work on your personal projects from different computers, whether your prefer Git or Subversion.
If you have 2 Dropbox accounts: one for work, and one for personal use for example, you can still use the above procedures. Use the sharing facility that Dropbox has, to share a repo folder between accounts. You can then still add code, and commit, just as you would if you were using a service like Github.