Here you can find some of the latest news from the mobile design and development world.

Using Dropbox as a Git repository

10 August

Someone in the CocoaHeads mailing list mentioned that it is possible to use Dropbox as a remote repository for Git and I thought I’d give it a try. It turns out it is actually pretty easy to set it all up so here are the quick steps for anyone who is interested (these are only applicable to Macs).

This is actually a great way to work collaboratively and remotely with other developers, or simply keep project files in sync between two different computers. In my case when working from home I’m usually on the iMac and on the road with the Macbook Pro so this works really well and allows me to work on the same project from different computers without the hassle of remembering to copy files across etc.

1) Firstly make sure you have the Dropbox app and Git installed on your Mac. If not, you can get Dropbox from here (direct download link) and the latest version of Git from here

2) With Dropbox and Git installed, you need to create a bare repository which will be shared with your Dropbox account. Open a Terminal window in your Mac and do the following:

$ cd ~/Dropbox
$ mkdir -p repos/your-repo-name
$ git init –bare repos/your-repo-name
Initialized empty Git repository in /Users/xxxxxx/Dropbox/repos/your-repo-name/

3) Now with our bare repository created, head to your project folder and let’s start a local git repo and link it with the Dropbox one. If you already have a local repo, skip to step 4:

$ cd ~/ProjectFolder
$ git init .
Initialized empty Git repository in /Users/xxxxx/ProjectFolder/
$ git add .
$ git commit –all -m "Initial commit"
$ git remote add dropbox /Users/xxxxx/Dropbox/repos/your-repo-name/
$ git push dropbox master

Essentially what we’ve done here was initialise a local repo, add and commit all files within that folder to the local repo. We then add a new remote location using the handle “dropbox” to this repo and finally push all the local changes to the “remote” repo (i.e. your Dropbox repo folder).

The rest is done automatically by Dropbox – your folder will be synced with your account and accessible from anywhere. For instance, if you wanted to clone the repo to a different machine, all you need to do is make sure Dropbox is installed and the folders are synced – and then issue the following command:

$ cd ~/Projects
$ git clone -o dropbox /Users/xxxxx/Dropbox/repos/your-repo-name/

If everything goes right, you should have a local copy of your remote repo already configured with your dropbox remote. You can start making changes to your project and when ready, push them back to the remote:

$ git commit –all -m "Changes made!"
$ git push dropbox master

And finally, when you want to sync the remote repository with your local copy, you can:

$ git pull dropbox master

I hope it helps.

Tags: , , , , ,

3 Responses to “Using Dropbox as a Git repository”

  1. Juliusz Gonera October 9, 2011 at 5:15 am #

    Why would this be better than just storing the project (versioned with Git) in the Dropbox folder?

  2. Uğur Özyılmazel December 1, 2011 at 6:07 pm #

    good trick! thanks

  3. GAN June 7, 2012 at 1:23 am #

    Juliusz: Because if you make changes on another machine, the changes will sync over immediately which is not the typical git workflow. And just like if you had no version control at all, just dropbox, changes to your local working directory will sync over immediately and overwrite local changes on the other machinen even before you have “committed” them.

    This way, you instead get something similar to an “upstream” repos that you can choose to push to (or pull from) only when you choose to do so. Different machines can handle their copy of the repository independently without overwriting eachother, the way a distributed version control system should work.