How to use Dropbox with SVN or Git for Cloud SCM

Share this article

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.

Frequently Asked Questions (FAQs) on Using Dropbox with SVN or Git for Cloud Source Control Management

How can I set up Dropbox with SVN for cloud source control management?

Setting up Dropbox with SVN involves a few steps. First, you need to install SVN on your computer. Once installed, create a new repository in your Dropbox folder. You can do this by opening the terminal, navigating to your Dropbox directory, and running the ‘svnadmin create’ command followed by the name of your new repository. After creating the repository, you can check it out to your working directory using the ‘svn checkout’ command. Now, you can add, commit, and update files in your repository as you would with any SVN repository.

Can I use Dropbox with Git for version control?

Yes, you can use Dropbox with Git for version control. Similar to SVN, you need to create a new Git repository in your Dropbox folder. You can do this by navigating to your Dropbox directory and running the ‘git init’ command. Once the repository is created, you can add and commit files as you would in a regular Git repository. The changes will be automatically synced to Dropbox.

How does Dropbox handle conflicts in version control?

Dropbox handles conflicts by creating a ‘conflicted copy’ of the file. This happens when two people edit the same file at the same time on different computers. Dropbox will save both versions of the file, with the conflicted copy having the user’s name and the time the conflict occurred appended to the original file name.

Is it possible to restore previous versions of files in Dropbox?

Yes, Dropbox allows you to restore previous versions of files. You can do this by right-clicking on the file in your Dropbox folder and selecting ‘Version history’. This will open a window where you can see all the previous versions of the file and restore the one you need.

How secure is using Dropbox for version control?

Dropbox uses strong encryption methods to protect your data. All files stored in Dropbox are encrypted using 256-bit Advanced Encryption Standard (AES). Dropbox also uses Secure Sockets Layer (SSL)/Transport Layer Security (TLS) to protect data in transit between Dropbox apps and servers.

Can I use Dropbox for version control with other cloud storage services?

While it’s possible to use Dropbox in conjunction with other cloud storage services, it’s not recommended. Using multiple cloud storage services for version control can lead to conflicts and data loss.

How can I resolve conflicts in Dropbox?

To resolve conflicts in Dropbox, you need to manually compare the conflicted copy with the original file and decide which version to keep. Once you’ve made your decision, you can delete the conflicted copy and rename the original file if necessary.

Can I use Dropbox for version control on multiple computers?

Yes, you can use Dropbox for version control on multiple computers. Any changes made to files in your Dropbox folder will be synced across all computers linked to your Dropbox account.

How can I share my Dropbox repository with others?

You can share your Dropbox repository with others by inviting them to a shared folder. You can do this by right-clicking on the folder in your Dropbox and selecting ‘Share’. Then, enter the email addresses of the people you want to share the folder with.

What are the limitations of using Dropbox for version control?

While Dropbox is a convenient tool for version control, it has some limitations. For example, it doesn’t support atomic commits, which means that if a commit fails, some files may be updated while others are not. Additionally, Dropbox doesn’t provide a way to view commit history or revert to a previous commit.

Andy HawthorneAndy Hawthorne
View Author

Andy Hawthorne is from Coventry in the UK. He is a senior PHP developer by day, and a freelance writer by night, although lately that is sometimes the other way around.

DropboxgitSCMSVN
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week