Saturday, July 24, 2010

Cheap git repositories with Dropbox

If you want professional source code repository hosting there are great providers like http://github.com out there where you can create free public or cheap private repositories.

But if you want something to back up local development or to collaborate in a small team for free, you might consider Dropbox and git.

Now one (perhaps big) proviso - you may have data sync issues if using this between more than one person so you'd have to coordinate commits.

You can download git for mac, pc or linux. See here:

http://git-scm.com/

There's a on OS/X git installer available on google code:


I use Gitbox app for the Mac:

http://gitbox.pierlis.com

And msysgit for Windows:

http://code.google.com/p/msysgit/

So you'll want to put your project under git source control first. There are plenty of tutorials to tell you how to do that.

Let's call the project mygitproject. Let's assume we're using a Mac to do this. Back up your source before trying this in case of errors.

Now, create a cloned git repository in our Dropbox account. The repository doesn't use a working folder as well, it just has the git system files. We will use this cloned repository to push changes to from our local project folder and it'll eventually sync to the Dropbox servers.

Change directory to your Dropbox folder:

$ cd ~/Dropbox

create a folder to hold the git repositories

$ mkdir git
$ cd git

create a folder for mygitproject

$ mkdir mygitproject

Now clone the mygitproject (assume it's in ~/projects folder). The mygitproject has to already be under git source control. Use the --bare switch so the working folder isn't used (just the git system files).

$ git clone --bare ~/projects/mygitproject

This will clone the repository to the ~/Dropbox/git/mygitproject/mygitproject.git folder.

Change to your project folder and to make it easy, create a remote link to your Dropbox repository called dbgp:

$ cd /projects/mygitproject

$ git remote add dbgp ~/Dropbox/git/mygitproject/mygitproject.git

If you want to push changes to the repository, perform your commits to your mygitproject then push them:

$ git push dbgp

You can do any change you like to your local repository and push the changes to your Dropbox account, including branches and tags and all the git magic. It's also pretty fast.

Only one warning - make sure Dropbox has finished caching the changes to its server before trying to refer to the repository from elsewhere.

You could go to another computer that had the same Dropbox account and do a:

$ cd ~/projects
$ git clone ~/Dropbox/git/mygitproject/mygitproject.git

This would check out the mygitproject to the ~/projects/mygitproject folder. You could then push or pull from it to collaborate. Again, beware the sync issues! I know this approach works but I waited for the dropbox syncing to stop first. Another user may not.

You can also share a Dropbox folder out to another Dropbox user and they see it in their ~/Dropbox folder, so this sharing approach might work too (though I haven't tested it).

But anyway, it's useful for making an offsite backup of your git repository.

If you need something more, try github, it's excellent. Dropbox is great software too.

No comments: