Mark Needham

Thoughts on Software Development

A reminder of the usefulness of Git

with 4 comments

Despite the fact that none of the projects that I’ve worked on have used Git or Mercurial as the team’s main repository I keep forgetting how useful those tools can be even if they’re just being used locally.

I ran into a problem when trying to work out why a Rhino Mocks expectation wasn’t working as I expected last week having refactored a bit of code to include a constructor.

I wanted to include the Rhino Mocks source code in our solution before and after the refactoring and step through the code to see what was different in the way the expectations were being setup.

My initial thought was that I could just check out the repository again in another folder and then include the Rhino Mocks source code there and step through it but unfortunately we have all the projects set up to deploy to IIS so Visual Studio wanted me to adjust all those settings in order to load the solution in the new checkout location.

I probably could have gone and turned off that setting but it seemed a bit too much effort and I realised that I could easily use Git to help me solve the problem.

I took a patch of the changes I’d made and then reverted the code before checking it into a local Git repository.

I updated the solution to include the Rhino Mocks code and then created a branch called ‘refactoringChanges’ so that I could then apply the patch that I’d created with my changes.

It was then really easy to switch back between the two branches and see the differences in the way that the Rhino Mocks was working internally.

The actual problem eventually turned out to be the way that the code calls Castle DynamicProxy but I didn’t get the chance to look further into it – we had learnt enough to know how we could get around the problem.

I’m in the process of including the source code for all the 3rd party libraries that we use in the solution on a separate Git branch that I can switch to when I want to debug through that code.

Sometimes I end up having to close down Visual Studio and re-open the solution when I switch to and from that branch but apart from that it seems to work reasonably well so far.

Written by Mark Needham

March 14th, 2010 at 12:45 am

Posted in Software Development

Tagged with ,

  • http://buffered.io/ OJ

    I do exactly the same all the time, though I use hg mainly instead of git. It’s made life a joy for me even when hg isn’t the chosen VCS for the project.

    I’ve only been on one project where hg was the main source of truth for our code, and it was by far the best experience in dealing with code contrl that I’ve ever had.

    Right now I’m stuck with SVN, but it could be worse *cough* tfs *cough*.

    Let’s hope that over time we start to see git and hg adoption increase in enterprise dev!

  • Bryan

    Mark,

    This _sounds_ like a great use of this technology and another reason why I (dare I say all of us) should give git a try.

    Though as someone who is trying to learn git, I’d love to see some examples of how you accomplished this.

  • http://galilyou.blogspot.com/ Galilyou

    Mark,
    Frankly, I don’t feel safe without Git. Same as you, we don’t have git as our main repository here, otherwise we are using a centralized VCS. Each time I attempt such a big change, I branch out an experimental branch and do whatever I want.

    @Bryan:
    If you want a quick introduction to Git, including branching, check this out:
    http://galilyou.blogspot.com/2010/01/into-git-and-loving-it.html

  • http://22ideastreet.com/blog Anthony Panozzo

    Mark, not sure if you use TFS with VS. If so, might want to check out http://github.com/spraints/git-tfs.