Eric’s take on git and svn

A friend wrote:

you seem to really like git. Whats your take on git vs svn?

It’s not a matter of git versus svn but more about what is git good at and what is svn good at. git and svn have different designs so they provide different solutions. Thing is, git does what it’s supposed to so well that it’s used as a substitute for svn. svn is meant as a central place to store source code and is basically cvs with some improvements. git is a content storage system with versioning, which are the two things needed to store source code. Though most git repositories store source code, it doesn’t have to. I run a personal wiki using git as the data storage and I’ve seen blog engines use git to store their content. There’s even a backup system written using git to store your files.

On a more pragmatic level, here is what I like about git over svn. I’ll use a large project I’m working on as an example because I use both git and svn with it and it’s a svn large repository:

  • 2.8 GB in size
  • around 6000 revisions
  • 197,902 files

Where git rocks

1. git is fast

Running any svn command on the project takes at least 60 seconds. git takes 1-2 seconds. svn commit and svn diff on the full project are typically run into the “go and make a sandwich” range. git barely gives me enough time to check twitter.

2. git stores the entire repository locally

Every single commit, log, and diff is local so git will never have to go out to the network until you are ready to share. svn in contract, stores only the last version locally and hits the network for the majority of it actions. (This is one cause for the speed difference in #1)

3. Since git has everything local, you can work offline

You can still work if the wifi is flakey or the proverbial “working on a plane”. By work I mean; commit, rollback, merge, diff, etc. svn in contrast will let you change your code but you only have one copy so you have to “Save as…” frequently.

4. git is efficient with it’s storage

Even though the project is over 2.8GB, git only adds 100MB to store the entire history of the project. Compare that to svn, where svn has two copies of every file (check inside those .svn folders if you doubt me).

5. Only one directory is needed to store the information for git

git will create only one directory in the very top level of your project called .git. This makes it really easy to rearrange directories in the project. No more .svn folder littering the project with hard-coded urls.

6. gitk

I have never seen such a great (ugly) tool that presents complex information so easily. Being able to visualize the different ways the code makes my job so much easier. All the visual svn tools I tried either sucked or didn’t work.

Sidebar

Next are the fun parts of git, which really shows how git works socially. I think it’s amazing when you give people the ability to work alone and isolated, that they end up drifting even closer together. But that’s another blog…

7. git is distributed

When you combine #2 and #3 you get the distributed nature of git. With everyone having a copy of the full repository, the central server is just another copy. This means at any time, the hosting server could blow up and with a few commands, any person with the git repository can have the repository back online. This makes the “central server” wherever everyone agrees to put their final changes.

8. git is easy to branch and merge

It gives you the freedom to experiment with different ideas and then throw away the bad ones. I can tell you from recent experience, merging separate development branches in svn is hard. Super hard. As in set aside a week to do it.

9. git allow collaboration

Since it’s easy to create a branch, it encourages people to take the code, modify it, and mold it into their idea. Sometimes this sucks, but most of the time it results in a lot of novel ideas. The great part is you call pull in the ideas you like and leave out the parts that suck.

Where svn rocks

1. It’s popular

Many people are using svn and there is a lot of tools built around it. But popularity isn’t correlated to good (i.e. Microsoft Windows and any other Operating System)

2. svn is stable

I’ve used svn for over 4 years now and it’s been rock stable as soon as I started using the fs-store option on the repository. Sure you can mess up your local copy but that’s mostly due to you pushing svn’s design too hard.

Where git sucks

1. It’s still a bit arcane

Some of the commands are difficult for a beginner and you need to be good at Googling if get stuck. But us Rubyists have Scott Chacon and the rest of the GitHub team if we get really stuck.

2. Git will not allow you to checkout only part of a project

This is hard especially if you are used to organizing your repository in a svn way (e.g. trunk, branches, tags). I think the biggest hurdle here is learning to keep separate repositories for the different parts or using clean branches for them. I still struggle with this myself.

Where svn sucks

1. It depends on the network

I don’t mind using the network since I only work at home on a fiber optic connection. But having to go out to the network in order to work enough of a interruption that I lose context. I’ve also been bitten by “the Subversion server is down” way too often.

2. Keyword Substitution is bad

I don’t mind the automation svn tries to do but if it’s going to modify files I add to it, I start to lose trust that the system will protect my data. I’ve never worked on a project that used keyword substitution right.

3. svn wastes tons of disk space

I know disk space is cheap but using twice the space for each file is just inefficient. That 2.8 GB project I have just ballooned to 6.6GB with all the svn copies. That doesn’t even include my hourly backups and S3 backups (minimum of 3 additional copies).

Conclusion

That said, these are my own opinions based on my habits and my work flow. I’ve only been using git since January 2008 so I’m still a bit new to it but it has made it dramatically easier for me to write code. At the end of the day, that’s what really matters. Does your tool git out of your way and let you do what you need to do? For me, svn didn’t but git does.

Eric

Update

Scott Chacon just created Why git is Better Than X, a website that compares git to hg, bzr, svn, and perforce.