Switching to Git

A little while ago, I wrote about how I’d started using a version-control system (Subversion) for my source code files. It worked well, but now that I’ve got a really good network-attached storage device (“the NAS” from here on), I wanted to put my repositories on there instead of keeping them on my local drive.

Subversion could easily handle that. The problem is, I use a laptop as my main machine specifically because it’s portable. I’m not always within range of my network, or any network for that matter. And a version control system is used for a lot more than just providing versioned backup copies of your code; I wanted to have a local copy of my repositories as well as the main one on the NAS.

There’s a name for such a creature: a distributed version control system. I’m not going to talk about the details, they’ve been described in lots of other places, in a lot more detail than I’m interested in. I decided on Git, since it seems to be the most popular of the open-source offerings, and offers easy conversion from Subversion (via git-svn).

(Note that although there are GUI programs for Git, they’re primarily viewers rather than full-fledged replacements for command-line operation, like the RapidSVN program I used for Subversion. I’m comfortable enough with the command line, but if you’re not, then Git is not for you.)

Distributed version control is different enough from centralized version control that it took me a few hours of experimentation to get it right. The trick, I found, is to create a “bare” repository on the NAS, and a regular (non-bare) one for your working directory (otherwise you get odd problems when you try to merge them).

To start with non-version-controlled source code, I set up the initial (local) repository by opening a terminal window, changing to the primary directory that contains the code, and issuing these commands:

    git init
    git add .
    git commit

The first one creates the hidden Git directory (containing the repository files); the second tells Git that you want to add all the files and subdirectories in the current directory to the repository; and the third actually puts the added files under version control. If you start a project from scratch, the second and third lines aren’t needed.

Then I created the “bare” repository on the NAS with:

    git clone --bare . /mnt/nas/project-name.git

(/mnt/nas is where to put it — the place that the NAS drive is mounted, in this case — and project-name is the short-name of the project.)

After that, you just need to link the two together. I’m sure there’s a simple shortcut for that (EDIT: there is, see Mattias Reichel’s comment below), but I did it the long way around: I went to the parent of the original directory, renamed the original directory to something else, and issued this command:

    git clone /mnt/nas/project-name.git

Once I made sure that the code was all there, I deleted the just-renamed original directory.

At this point, you can use the local repository the same way you’d use Subversion; the commands are different, but the concepts are similar enough that you can get over that quickly. The QGit program makes it easy to view the different revisions and compare files from them (though it’s different enough from RapidSVN that it took me a while to figure out how to do things in it). When you want to send your local changes to the repository on the NAS (for backup or long-term storage, or to share them with another machine), you just switch to the local directory and call:

    git push

And fetching the latest changes to another clone of the repository (presumably on another machine) should be just as simple, though I haven’t tried it yet:

    git pull

That’s all there is to it. 🙂

Converting the Subversion-controlled projects to Git-controlled ones is fairly simple too, but I won’t go into that here. See this page for details on that. You can even leave your projects under Subversion and use Git locally, though I didn’t try that (Git stores things a lot more compactly, which is more efficient, and I’m all for efficiency).

The end result is that all my projects are now version-controlled with Git, with their primary repositories on the NAS and (for the ones that I’m actively working on) a local repository on my main machine. I have full access to version-control no matter where I’m working, and a RAID-1-protected backup as soon as I return to the office.

I love it when technology works. 🙂

“InstallerApp For Mac Installs Jailbreak Apps Without Jailbreaking Your iPhone”

I was quite surprised, a few days ago, when my official Apple “iPhone Apps” RSS feed came up with something called “InstallerApp 1.0,” because the description says that it’s a way to put iPhone apps that currently require jailbreaking on your unjailbroken iPhone:

InstallerApp is a native Mac OS X application that allows you easily download applications from Installer and Cydia directly onto your computer, and install them to the iPhone connected with USB cable. It will install all the needed components even on non-“jailbroken” iPhones with the built-in Pusher technology.

Isn’t this what Apple is doing their utmost to prevent? If so, how did this program get past their ever-watchful censors?

Network-Attached Storage

I’ve long had a vision of the perfect computer storage device. It’s physically small, but holds an absolutely ludicrous amount of data. It’s instantly available to all my computers and other electronics, but I have full control over who can access its contents. And it’s reliable enough that, with the occasional off-site backup, I never need to worry about losing any of its contents.

Such a beast doesn’t exist. A few years ago, I’d have said it probably never would, but my opinion on that has changed. Technology has advanced far enough that I can not only see it affordably happening one day, I’ve actually put together something that approximates it now.

A couple days ago, I picked up a D-Link DNS-323 Network-Attached Storage Box (“the NAS” from here on). It’s essentially a tiny headless computer that exists solely to act as a network file server.

I used to think that RAID-5 was the be-all and end-all of storage solutions, but after hearing Joel Spolsky and Jeff Atwood discussing it on a recent Stack Overflow podcast (number 34, maybe?), I realized that it wasn’t all it was cracked up to be. So I started looking into RAID-1, which makes two identical copies of everything on different physical drives. The idea is that, if one drive fails, the system can keep working from the other one until you replace the failed drive, whereupon it copies all the data to the new drive too. This NAS supports it, which is part of the reason I decided on it.

But RAID-1 has one major drawback: you only get half the usable storage that you pay for. If you set up two 250GB drives in a RAID-1 configuration, you only get 250GB of storage out of it, not the 500GB that you would have if they were set up separately. The capacities of inexpensive hard drives have only recently gotten large enough that I felt it was worth paying for two of them to get the added protection against drive failure.

So yesterday I picked up two Western Digital 1TB hard drives (that’s one terabyte, or one thousand gigabytes, each) to pop into it. I was careful to get drives that weren’t from the same manufacturing batch (though I had to go to two different computer stores to do it), because as Joel described in the aforementioned podcast, drives from the same batch are likely to fail at about the same time. I popped them into the NAS (serial ATA drives, no tools, cables, or jumper configurations required — nice!), told it to format them as a RAID-1 array, and… that’s it. In less than ten minutes, it was done.

How does it stack up to my vision? Well, it’s physically tiny — not much larger than the pair of 3.5″ hard drives that it contains. One terabyte of storage should be enough to hold every bit of digital data I own now, several times over. My network handles both the availability and security points, and I can use TrueCrypt to make an encrypted drive container on it for things that need to be protected against physical theft of the device. And with RAID-1, hardware failure isn’t likely to be an issue, so I don’t have to be quite so anal about keeping off-site backups. Not a perfect match, but pretty close. 🙂

You may recall that I had bought a similar beast, the MyBook box, about a year and a half ago. I’ve been fairly happy with it, but the D-Link is better — it’s physically smaller, has twice the capacity, is a lot quieter and more power-efficient, and has a few other really nice features (e-mailed warnings of failed drives or other problems, firmware stored in flash memory instead of on the disks, shuts down the drives when they’re not in use, etcetera). It’s more expensive, but the added features are worth the cost, especially the silent operation.

The other question that I know some of you are thinking is, if I can put together a desktop computer so cheaply now, why didn’t I just build a new desktop system to handle this? It’s a legitimate question, and one I considered; I have enough parts on hand that I could have done it for about the same price, maybe slightly less. But I really didn’t want yet another computer here (we’ve already got three laptops, two working desktops, and three desktop carcasses waiting to be resurrected), and the NAS eliminated the need to deal with setting up the software and such.

All in all, I’m quite happy with it.

New Computers — Cheap and Silent!

I’ve put together two new computers recently, one for my mother-in-law and one as a replacement for a system that died here this week. I used some parts I already had from their predecessors (the monitors, keyboards, mice, hard drives, and CD/DVD drives), but even considering that, they were extremely inexpensive — the motherboard (with integrated everything, including a pretty powerful nVidia video card), a pretty fast dual-core AMD processor, and 2GB of memory at my local white-box shop cost me less than my 16GB iPod Touch at Costco. My mother-in-law’s system used the same motherboard and processor, only 1GB of memory, and included a power supply and an unbelievably nice case, for about the same price as the Touch.

Even more shocking was just how silent they were, once I got them together! My niece was visiting my mother-in-law’s house and, when she saw the computer, she had to ask “is it on?” (It was.) 🙂

Computers have come a very long way since I built my first one.