Nick Dimiduk blog et al.

Dropbox as a Git Archive

You use git and have a Dropbox account, right? Here’s a little trick I use from time to time for archiving Git repositories. Create a bare repository in your Dropbox account and push a mirror. Now you can delete your local sandbox, but you’ll still have the full history available if you need it later. Sure, you could set up private repos on Github, but that’ll become expensive fast, while Dropbox is free, at least from the beginning.

The first step is creating the bare repository in a directory managed by Dropbox. A bare git repository tracks file revisions only; it doesn’t contain a working copy of the files themselves like a regulare repository does.

[~] $ cd Dropbox/repos
[~/Dropbox/repos] $ git init --bare foo.git

Next, add the dropbox repository as a remote on your working repository. Once you’ve done that, you can interact with it just like any other remote repository. For the first push, you’ll want to use --mirror so that both branches and tags are pushed.

[~/Dropbox/repos] $ cd ~/repos/foo
[~/repos/foo] $ git remote add dropbox $HOME/Dropbox/repos/foo.git
[~/repos/foo] $ git push --mirror dropbox

You can also use this trick to host a repository shared across multiple machines. Each one has the bare repo configured as a local remote and Dropbox will handle syncing the changes across them.

[hostA:~/repos/foo] $ git commit ...
[hostA:~/repos/foo] $ git push dropbox
// magic sync happens
[hostB:~/repos/foo] $ git pull dropbox

Be careful to only push changes when your Dropbox client has everything in sync. The bare repo contains multiple files, so two simultaneous pushes will likely corrupt it. Don’t say I didn’t warn you!