How to use Dropbox with SVN or Git for Cloud SCM

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.

Overview

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.

Dropbox Revisions

Dropbox Revisions

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:

git init

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:

cd ~/sample_project

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.

Finally

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.

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • Juan Barrientos

    This is a clever and very useful idea, thanks!

  • Davo BRUNSTEIN

    Hi Andy,

    I don’t quite understand what the benefit is to use git or svn together with Dropbox.
    I’m a Dropbox user and have several projects in git, and we use Dropbox as a collaboration tool.

    We share the code versions on git and documentation files in a shared folder in Dropbox. I really don’t see why to clone into Dropbox the git folder. If I need to have the code in a new computer, I create the developer folder and pull out the code from git; and install the Dropbox client, which creates and synchronizes the shared folders.

    Sorry, but I don’t see the reason to have the project (code) folder under Dropbox; it is already shared in git.

    Thanks,
    Davo

    Winnipeg, MB

    ————————
    Do you use Winnipeg Transit?

    iRide Winnipeg is the coolest way to ride the transit system
    Check it out from http://www.iRideWinnipeg.ca

    • Attila Fulop

      @Davo: I think the real matter is: “it’s a lot cheaper than using private repositories on Github for example”. i.e in case you need a _private_ repository for small projects

  • Mark

    https://www.insynchq.com/ – same as dropbox but uses google docs storage (can still upload any file type), meaning it is 8-10x cheaper with 1GB free.

  • Carlos

    Great article I found it very useful.
    I use Dropbox and Evernote and I Always find it amazing when people use it to solve problems with simple solutions.

  • Panayotis

    Nice idea. Thanks for posting.

  • Marcus Barnes

    Hi, Andy,

    Thank you for the article – it was just what I required for a small project that I’m working on and need to snyc between multiple computers without having to purchase/set up a private remote repository. I’ve added a link to your post on my list of useful or interesting Git related blog posts: http://www.marcusebarnes.com/771/version-control-with-git/

    Have a great day!

    Marcus

  • Adrian Hedley

    Hi theis is a great idea, especially if you are working behind a firewall and you cannot access svn directly but dropbox or insynchq still works.

    I have tried it and it works, however i experienced problems when committing to svn. After reviewing the logs in event viewer, the issues were related to txv-current-lock and write-lock.

    Basically to fix it i had to delete these files and committing worked. I posted a link in stack overflow. you can get more details here : http://stackoverflow.com/questions/4661623/svn-txn-current-lock-permission-denied/9669423#9669423

  • Laks

    Ah.. very clever.

  • nxb3942

    Depending on whether you want to use DropBox for consumer or businesses purposes, it may or may not be right for you. For businesses in many regulated industries, DropBox is not compliant. Their website clearly states this:
    https://www.dropbox.com/help/238
    Dropbox Enterprise File Transfer from Thru is the secure solution for businesses and enterprises. Their solutions have been working for large businesses for ten years without a single security breach.
    http://www.thruinc.com/solutions/dropbox-enterprise-file-transfer/
    http://www.thruinc.com/products-services/secure-file-transfer/

  • Ivan

    Hello,
    I am the co-founder of Codeanywhere. Codeanywhere is a web based code editor and we just added a GITHub client, altough you cant commit yet you can view everythng and copy files to FPT, SFTP servers, Dropbox and cloud disk (Sandbox).

    The new version with Commits comming next month.

    Try it out and let us know what you think http://codeanywhere.net