Tuesday, December 11, 2012

DropBox as a GIT Central Repository.


If you've been reading my blog, it should be clear by now that I'm a bit of a fan of the Git version control system.
I've been hosting some projects on Unfuddle for a while now, but have not been very happy with fiddling with SSH keys and setting up the central repositories through the Git Extensions for Windows. It works, but that's all I can say.
Another issue I was not looking forward to tackling was setting up TeamCity to pull from Unfuddle. I haven't tried, and for all I know it might work great, but if there's a perfectly good shortcut that I can take, I'll take it!
A few days ago I saw some tweets from people mentioning Git and DropBox as a combo. Unfortunately, I can't find the messages any more as Twitter's retention policy seems to be very aggressive. So I decided to try doing it myself.
The advantages of having a Git repository in DropBox are that:
  • it does not rely on a service that (for all I know) might go out of business one day;
  • it prevents me from having to create SSH keys as credentials;
  • it makes it easier to point TeamCity to a central git repository (which is in fact on the local disk);
  • the central repository is always synced to all of my dev machines and to the DropBox server, so there is multiple backups in case of catastrophic failure;
  • you will always have the ability to push changes to a central repository, even if you have no (or intermittent) internet connectivity;
  • if you have to work without internet connectivity, but with network connectivity, you could just set-up a network share and push and pull to each of the repositories that way.
I'm wildly enthusiastic about the distributed nature of the Git version control system, it really does allow me to work from anywhere and in any way that I want.

I am assuming that you have DropBox installed and that you are using the Git Extensions that I've mentioned in earlier blog posts on Git.
I've created a folder somewhere in my DropBox folders that will hold my Git repositories. In there, I've created a folder called "Example.git".
Next, I created a new Git repository using the Git Extensions. When you start Git Extensions, choose "Initialize new repository" from the "Commands" menu.
I created a "Central repository, no working dir" in the "Example.git" folder.
gitdropbox01
Then, in the folder that holds my Example project, I created a personal repository, as I would do normally when putting you project under version control (again through "Commands", "Initialize new repository").
gitdropbox02
This will open up the repository in Git Extensions. The first thing I like to do is hit the "Edit .gitignore" button, add the default ignores and commit that as the initial commit.
gitdropbox03
With that inital commit out of the way, I will add a remote from the "Remotes" menu.
I've name the new remote "DropBoxExample" and instead of entering a URL, I point to the "Examples.git" folder that I created earlier.
gitdropbox04
After clicking the "Save" button, Git Extensions will ask if I want to automatically configure the default push and pull behavior, I've skipped this step because the folder on the disk is not actually a server that understands commands. Then I closed the "Remote repositories" window and start pushing the master branch to the remote.
gitdropbox05
And got a confirmation message, it worked!
gitdropbox06
Now I am able to actually set the pull defaults, so I go back to managing the remote, go to the "Default pull behavior" tab to choose the defaults from the dropdown lists and clicked "Save".
gitdropbox07
All done!
I went to my other machine and created the same "D:\Dev\Example" folder.
I opened up Git extensions and initalized the folder as a personal repository. Then I was able to add the remote repository in exactly the same way, instead of entering a URL, I pointed to the "Example.git" folder in DropBox, saved the remote and pulled from it.
To my delight, I saw the .gitignore file appear immediately and noticed that I had received the commit history from the other machine. Success!
Of course I then proceeded to add a Visual Studio project, pushed it to the central repository, pulled it in on the other machine, and again, everything appeared as I hoped it would. Success!

No comments:

Post a Comment