Saturday, October 3, 2009

Dropbox and GIT

This semester (fall 09), I have attended a project-based course at IU, Bloomington. It's a network class. First project is to use libpcap to read packets from capture file (.pcap) and analyze each packet (e.g. IP, TCP, UDP, header size, flag, checksum). Everything in the project went fine, until I want to find some personal version control to use with it. Assembla used to provide private repository for free, but now they change their policy. So, I looked around and found Unfuddle, it provided 100MB private project with unlimited repositories. However, it allows only 2 people in project for free edition. It should be work for me because I would use it alone, still it didn't satisfy my need. Finally, I came across Dropbox, which gives you 2GB of space and the ability to share folder with your friends.

I first used Dropbox about 1 years ago when I was at home. I wasn't impressed with it because it seems to be very slow in Thailand. Now, I'm in U.S., I have to say it a lot faster. Although I get used to using SVN, my solution is to use it with Git repository because it's distributed version control instead of centralization. Dropbox has already provided version control you can revert or undelete your files, but Git will provide more flexibility for programmers.

The way to do it is simple, I just install git and Dropbox on all my machines (Laptop and department's machines). Then create Git repository folder you want to share via

$git init

and add all files in folder or files you want through

$git add .

After you install Dropbox, it will become like a folder on that computer. Thus, I just clone Git repository to Dropbox's folder. For example, if my Git repository is at ~/ptangcha/network my command would be

$git clone ~/ptangcha/network ~/Dropbox/network

Done! I have Git repository in my Dropbox. Now, if I want to get my code in other machines, I just clone Git repository from Dropbox to folder on machines.

Since my code will be run on Linux machine (no libpcap on windows :( ), I don't want to to convert LF (Line feed) to CRLF (newline for windows) every time I add new file. Git converts it to CRLF because it detect that my repository is on Windows. So, I just configure git with this code.

$git config core.autocrlf false

I'm still newbie to Git. There are many useful command and many things to play with before I can fully benefit from it.


Resources:
- http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

3 comments:

Anonymous said...

When cloning your repo consider using --bare (or --mirror).

This means that Dropbox will not contain a working copy of latest files, only the history located in .git.

This is recommended practice for 'master repos' that do not need a working a copy

Andreas said...

Hi!

The idea of using dropbox for sharing repositories is found around the web also for hg and bzr.

Please don't do this!!!

If two persons share one repository and both make at the same time changes at their "dropbox-copy" the repo ist not in sync.

Then dropbox wants to sync the folders from the two computers and.. then... ?

Dropbox does not know anything about the git internals, so how should this two changed folders should be merged?

brgds,

AO

Patanachai said...

Hi Andreas,

Thank you for the comment.

I personally used this approach for myself. As I posted, I keep my Dropbox repository as "central and online copy" and I didn't work directly from it. Just pull and push as need.

I agree that sharing Dropbox folder will cause a problem. As I know, Dropbox will create a conflict file for you if you modify the same file at the "same" time (it is not actually the same, but it might mean file is in sync with server).

For git, I don't know what it did when two persons try to make change to the same repository at the same time (lock? branch?) in local file system, and online hosting (Github, etc.).

In my opinion, Dropbox sharing can be viewed as a slow file system or a person with interrupted internet connection (need times to be consistency). If you know how to deal with this problem, you can use Dropbox as shared repository.