Showing posts with label dropbox. Show all posts
Showing posts with label dropbox. Show all posts

Friday, March 4, 2011

git sharing with dropbox

I recently posted about using Dropbox as a git server: git push dropbox.  I have since refined this process as I became more familiar with git and fine tuned my development workflow. So here's an update on how I now use Dropbox to both share and backup my git repositories.


(note: in the examples below "$" is the bash prompt; all commands are entered in the OS X Terminal. I'm very much an old school UNIX command-line guy! However, on other platforms, all commands will be possible from your favourite git client.)

Initialise a git repository for Project, if one does not already exist:


  $ cd Project
  $ git init .
  $ git commit


Create a git server repository in Dropbox.  It is initialised as "bare" which means it won't hold a working copy of the repository. It is a shared repository only.
  
  $ mkdir ~/Dropbox/git-server/Project.git
  $ git init --bare  ~/Dropbox/git-server/Project.git

In the local repository, add the Dropbox repository as the remote origin then push the current branch up to it.

  $ git remote add origin ~/Dropbox/git-server/Project.git
  $ git push origin master

That's all there is to sharing and backing up your project repository.  Whenever you need to (I generally do it after every commit) you can "git push origin master" again to update the Dropbox repository.

On another computer, to clone a copy of the project repository from Dropbox:

  $ git clone ~/Dropbox/git-server/Project.git
  $ cd Project
  $ git status

To update a clone from the Dropbox server:


  $ git pull origin master


Too easy!

Some other useful commands for examining the remote repositories:

  $ git remote
  $ git remote show origin


And note that you can add other remote repositories.  So you could add a github repository so you can selectively push stable snapshots of your project to github for public consumption, while keeping work-in-progress commits stored locally and backed up in Dropbox.

Wednesday, January 19, 2011

git push dropbox


Git is great and Dropbox is awesome and recently I found a way to combine the two.


I host my open source projects on github (as well as bitbucket – I'm a happy Mercurial user as well) but there are some private and/or client projects I don't want to store on those sites.


Git, of course, doesn't require a server repository.  So you can work locally while still having full version control.  However, I like the comfort of syncing to an offsite repository so I tend to push my changes to the remote server multiple times per day (also, old svn habits die hard).


For git repositories that I don't want hosted on github, I push to a git repository sitting in Dropbox instead. The push is handled locally and Dropbox performs all the magic of syncing to the cloud (my offsite backup) and to my other computers/devices (switching dev computers isn't a problem). Simple, fast, nice.


Here's how I set up a bare git repository in Dropbox for a project:


$ mkdir ~/Dropbox/src/git-server
$ git init ~/Dropbox/src/git-server/MyProject
$ cd ~/Dropbox/src/git-server/MyProject
$ git config --bool core.bare true

$ cd ~/src/project-git
$ git status
# On branch master
nothing to commit (working directory clean)
$ git push --mirror ~/Dropbox/src/git-server/MyProject

$ git remote add dropbox ~/Dropbox/src/git-server/MyProject
$ git push --mirror dropbox
Everything up-to-date



The first batch of commands initialises a new git repository.  The repository is flagged as bare so that we can push all branches (including the working branch).

The second batch simply pushes a development repository to the Dropbox one.  I use --mirror to push everything over.

The third batch of commands set up a shortcut for the Dropbox repository.  I name it "dropbox" so from then on I only have to do "git push dropbox" to push to it (with or without --mirror as required, although I usually use it).

Update: I have since refined my git/dropbox workflow: git sharing with dropbox.