Using Dropbox as Git remote server

I frequently use GitHub to maintain a lot of my personal projects, minor hacks and if I am upto it, contributing to other open source packages. It is like this free (almost) unlimited remote server where you can push all your code. The downside is, unless you pay them some money, all your code ends up being open to everyone. Now if for some reason, you don’t want the code to be public, you might have to buy private space on GitHub or maybe try and apply for the free educational repositories. (Or move to BitBucket, but again the free ones are limited).

However, there is a cheap, albeit risky alternative to that – You can use your Dropbox space (Or Google Drive – if you are a fan of Google reading through your stuff) as a free Git remote server! This is not a fool proof method and the chances for conflicts arising are high if multiple users are pushing code, so it is best recommended for personal work, where only one person is pushing code to the remote repo.

A lot of people have done this before, so this is old news, but I think its a decent hack and worth telling people about it.

The Steps

Let’s move to the command line and set up our repository!

Step 1 :  Move to your Dropbox folder and create a folder (Git in our example) where you will be creating your repositories and initialize a bare repository like this:

 cd ~/Dropbox/Git
git init --bare dropboxrepo.git 

This will create a folder with the name dropboxrepo.git and inside it, you can see that it has all the essentials for a git repository.

Guts of the bare repository

Guts of the bare repository

Now technically you are making this repository on your local machine, but since it is inside the Dropbox folder, you are syncing it to their servers as well, and can access the folder contents anywhere.

Step 2 : Now go the local repository, where you maintain the code that you want to push to your remote repository, and add the above folder as a remote like this:

 git remote add dropboxremote ~/Dropbox/Git/dropboxrepo.git 

Basically what you did here is  add the path to your dropboxrepo.git folder as a remote alias. So now the alias dropboxremote will refer to this folder and will be identified as a remote repository.

Step 3 : Now that you have initialized a remote repo and added it to the remote alias in your local repo, you can now push your code like this:

 git push -u dropboxremote master </code>
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 458 bytes, done.
Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done.
To /Users/abhinav/Dropbox/Git/dropboxrepo.git
* [new branch] master -> master
 Branch master set up to track remote branch master from origin.

After this, you should see the Dropbox spin sign for a while as it syncs all your files. However you will notice that after syncing, you don’t see your files in the folder but the same files you saw before (they are modified now though). But don’t worry all your files are synced. You can now follow the same steps as above and clone this repository on another machine and you will see all your committed code right there!

Word of caution

As I said before, this is not exactly the best way to have your own private remote server (It’s free!) and it comes with its own dangers. Firstly, if you push or pull while the folder is still syncing you might encounter errors like this:

error: unable to find ea2ae105b8955b3f73d79065bc52ee3126cd2e4f
error: refs/heads/master does not point to a valid object!
Your configuration specifies to merge with the ref 'master'
from the remote, but no such ref was fetched. 

If you see this error, just wait for the syncing to finish and try again. If it still doesn’t work, you will have to delete your current remote repo and create a new one and try again.

The above issue occurs frequently if there are a lot of contributors pushing the code to the same remote repo. Of course you can be careful and avoid them, just don’t pull/push while syncing!

I recently started using this method to maintain some of my private projects and it works just fine!

Happy tinkering!

1 comment
  1. filipe said:

    Thanks for the simple post, but with many important informations.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: