Anish Athalye

git-remote-dropbox

TL;DR version: now there is a good way of using Dropbox as a true Git remote: git-remote-dropbox.

We keep all of our files in Dropbox. Wouldn’t it be great if we could keep our code there too?

I have two different demands for storage space:

  1. To have files distributed around computers and have them synchronized in multiple places

  2. To use git to formally control version of individual files, and use a central storage to keep multiple clients in sync.

There is not a practical way to use Dropbox for hosting Git projects. That’s a major limitation.

There are a bunch of guides on the Internet that describe various ways to use Dropbox and Git together. Most of them recommend keeping a bare Git repository in a folder synced by Dropbox and using a folder-based Git remote.

This seems to work okay for the most part. Except when it doesn’t:

A quick note about problems … if something gets messed up in the repository … wait until Dropbox finishes syncing to make sure it’s not just out-of-date files, then if the problem still exists, delete your Dropbox repository and create a new bare repository

That’s not a good user experience. It’s not even safe to use with a single user, never mind using it for collaboration. There are tons of people who have said that using Git with Dropbox in this way is a bad idea.

Cause

The root cause of these problems is that the Dropbox desktop client is designed for syncing files, not Git repositories. Without special handling for Git repositories, it doesn’t maintain the same guarantees as Git. Operations on the remote repository are no longer atomic, and concurrent operations or unlucky timing with synchronization can result in a corrupted repository.

Traditional Git remotes run code on the server side to make this work properly, but we can’t do that.

Solution

It is possible to solve this properly. It is possible to use Git with Dropbox and have the same safety and consistency guarantees as a traditional Git remote, even when there are multiple users and concurrent operations!

For a user, it’s as simple as using git-remote-dropbox, a Git remote helper that acts as a transparent bidirectional bridge between Git and Dropbox and maintains all the guarantees of a traditional Git remote. It’s even safe to use with shared folders, so it can be used for collaboration (yay unlimited private repos with unlimited collaborators!).

With the remote helper, it’s possible to use Dropbox as a Git remote and continue using all the regular Git commands like git clone, git pull, and git push, and everything will just work as expected.

The way it works is actually quite straightforward. For someone interested in the internals, I’d recommend reading the design document.