Why Git Makes Sense for Me
Tags: 
Date: 11 June, 2010 - 06:15

Over a year and a half ago, I caught one of Travis Swicegood's sessions on "Getting Git." At the time, I didn't but it had interesting implications, so I bought his book "Pragmatic Version Control Using Git" and promptly forgot about it.

Fast forward a year and I found myself buried under web2project patches. At the time, all of them had to go through a few of us to make it into the core Sourceforge repository and the diffs started piling up. Needing a new approach where I could handle patches faster and easier, I decided to spend some time and actually explore Git.

First of all, Git is a Distributed Version Control System (DVCS), so it's an odd beast. Instead of having just one central repository which everyone interacts with throughout the project, you get your own. And every team member has their own. And anyone else can make their own. The biggest benefit of this is the ability to commit locally - and get related features like branching, merging, commiting, rollbacks, and diffs - without having to share with everyone else.

Some people - like Rich Bowen at Notes in the Margin - have concerns that this could easily result in developers working disconnected from the community and suddenly sharing huge batches of unreviewed code all at once. I'll admit that I have been guilty of this one once or twice, but I believe this is more of a workflow issue than a tool failure. If you explore Eli White's presentation on Code & Release Management (under the PHP Tek X heading). Starting on page 17, he talks about the concept of Feature Branches. If you're using a DVCS, this is an idea workflow, especially if the features are "small" and the codebase is well-segmented.

Next, Git allows for cheap branching, merging, and switching between branches. Coming from the SVN world, this didn't make sense until I adopted the Feature Branch approach. In my local development, if I know a Feature is big or a fix is wide-ranging, I make a branch and work on that. Once I'm confident in it, I merge it back with the master (trunk in SVN terms) and push it to the central repository. As a rule of thumb, once something is bigger than a couple commits, I branch as necessary.

Of course, it's possible to get in over your head and what you thought was a quick fix ends up interacting with all different parts of the system. Ideally, our systems aren't like that.. but we are in the real world. So if something ends up being bigger than you expect or even if you forget to branch, you can branch from an earlier commit with one command. Alternatively, if you think you've been commit-happy and made too many, you can merge them as needed.

Next, you have to understand that a DVCS tracks individual changes, not states of files. If I was giving you directions to the grocery store, SVN would be the equivalent of giving you pictures of each intersection where you had to turn and no other information. Sure, it might get you there but since you don't know how far it is between turns, it could get painful quickly. Alternatively, if I said "From my house, drive 1.45 miles north on First Street to Washington Ave. Turn right and drive east 2.5 miles to 3145 Washington Ave. Go in the north-facing entrance, walk 55 feet to the elevator, get in elevator, press 3.." There's a whole new level of information available.

Fundamentally, this is why merging in other systems is usually difficult. If something changes, it can be difficult or even impossible to adjust. The first explanation (aka how SVN works), may not be enough for the system to be able to handle simple changes properly. The second explanation (aka how Git works) offers an excruciating level of detal that includes multiple cues on how to get to the destination. Now, if you have road construction or others' commits changing everything beneath you, you have enough room to improvise and make educated guesses on the next step.

Github captures this all pretty well. As people fork your project and make their own changes, 90% of the time, it's trivial to merge them back into your core system. In fact, in the dozens of commits I've collected from people, only a handful have been problematic and most of those were because the same fix was applied already via another person.

Finally, Git is not perfect. With all of these useful features and concepts, the tool set is still relatively immature. I've heard numerous complaints with the Windows client, but since I'm on Ubuntu, I don't experience that. Next, the individual commands are incredibly powerful and normally well documented but the error messages are completely unexpressive. Stack Overflow has helped quite a bit with it, but the Git community should incorporate some of this back to give us meaningful errors.

Some criticize Git for the lack of a central repository. Since this is how Github is setup by default, it seems a weak criticism at best. Prior to writing this post, my biggest criticism was completely based on ignorance. I believed the hook system was mediocre at best. I'm happy to say that after trying this thing called "searching," I found a great deal of information including many fully formed scripts.

If you're looking for more information, the Git Documentation site is great but the Visual Git Cheat Sheet is even better once you have the basics.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Interesting, but not yet taking the plunge

I've dabbled, but I have to say I'm still an SVN person for the time being. One of the reasons I'm still hanging on is for the svn:externals feature. To my knowledge, git doesn't have a way for me to manage a code base that pulls in code from another repository. I'll often have javascript or other libraries externally pulled in. Instead of putting them all into my own repository I just designate which rev/branch I want included.

Good Point

I don't use svn:externals, so I haven't hit the same problem. If I recall correctly, tThe Zend Framework (led by Matthew Weier O'Phinney) uses svn:externals quite a bit and has started using git quite a bit more. I'm not sure of their approach, but it might be worth checking out.

Of course, I'm still a git newb as evidenced by a commit the other day. In web2project, I merged in my timezone branch into master. While my git repository browser showed all the commit messages, when I commited back to svn, it all came in as a single commit without the useful messages.

Doh.

External Dependencies

Handling external dependencies isn't really an SCM problem, but people have been conditioned to expect their SCM software to handle it. This issue is better handled by another tool. You should not use a screwdriver to hammer in a nail, but if your screwdriver is built just right then it might work.

I wrote a tool specifically to do external dependency grabbing, but I cannot release it due to some pesky copyright and licensing issues. I shall work harder on getting those resolved, since its few fans (limited in number) would really like to use it in more of their projects, too.

Interesting perspective

Thanks for the perspective, Michael. The external dependency is such a convenient feature of SVN and I hadn't thought of it as a mixed responsibility. It solves the problem of people downloading a copy of third party libraries and storing it in the their repository.

If your tool goes public I think it would be a most useful thing.

The git way

Git does have a feature that allows you to manage external dependencies. Check out git submodules: http://git-scm.com/book/en/Git-Tools-Submodules

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <img> <p> <blockquote> <strike>
  • Lines and paragraphs break automatically.

More information about formatting options