Monday, September 30, 2013

Private Git Repos on Dropbox

Github is great, but if you want to keep your code non-public they try to charge you 7$ a month. I think that capability is great for organizations or companies wanting private code repos on the Internet. But I'm already subscribed to enough $10ish a month services and I didn't want another one draining my bank account for no good reason. Bitbucket allows for unlimited private repos, and looks pretty awesome (thanks Phil). But after some playing around I accomplished the same by just using git and Dropbox. This is nice, because now that Dropbox has me hooked on file synchronization I've been planning to migrate off of it using rsync anyway if they break their service model or I just get motivated one of these weekends.

Here's how you can do the same. I'm assuming you have basic familiarity with git and Dropbox.

Go to your dropbox folder and init a bare repository:
cd ~/Dropbox/code/
git init --bare myproject.git

Now go to your local workspace directory and git init your code:
cd ~/workspace/myproject/
git init .
git add .
git commit -m "first commit"

Now add your dropbox as the origin repo:
git remote add origin ~/Dropbox/code/myproject.git
git push origin master

That's it, you're done. Now you have all the functionality of a code repo synced across all of  your machines to work on all that code that you're not ready to give to the world yet. If you're compiling or generating lots of data, don't forget to use your .gitignore file to prevent those being copied to your dropbox and using up your quotas. When you move to a different computer for the first time, git clone ~/Dropbox/code/myproject.git. From then on, just remember to do a push/pull when you start or finish working on the code.

If you like this tip, share my blog url.