CodePrairie .NET

South Dakota .NET User Group


Getting started with the Castle git repo

Before we dive into commands I feel the need for a little rationale. I'm not going to explain all the virtues of GIT as google will happily do that for you, I am however going to explain why I need to use it.

I have 5 separate projects that all use something from Castle. Keeping track of which project uses which build can be very difficult espcially since I always run from castle trunk. Subversion would have me create a separate vendor branch in each project and stick mirror the castle repo there. That is all well and good until I start fixing bugs or making enhancements. As soon as that happens things get hairy.

My solution is to have a git repository that mirrors the castle svn but contains separate branches for each product that is using it.

On my system git branch -a will list something like









Now when I need to jump between projects and dig into castle source it is as simple as

git checkout Product1/current

I can also freely move patches around and stay up to date with the latest and greatest being produced by the castle community.

Setting up the git mirror can be a time consuming process. You do have the option of only pulling history up to the last N revisions, but I like full history so I can visualize how things have changed. Pulling the full history takes a while and puts an increased load on Hammett's servers.

That is why I did the full import and published the mirror to which provides public git hosting.

Now the good stuff. To get started you want to install cygwin + git. Git is a cygwin package so this is easy. I believe there is a MinGW port in progress, but I already had cygwin so this was easy for me.

Now to clone the repo simply do

git clone -n --origin castle-svn git://

These are not the standard options, so let me explain.

-n tells git to not checkout anything after it copies. I like this because a master branch isn't very meaningful to me in this context.

 --origin castle-svn tells git to place branches in from the remote repository into /refs/remotes/castle-svn instead of /refs/remotes/origin (the default). This again is just for simplicity on my part. I like doing git checkout trunk castle-svn/trunk better than git checkout trunk origin/trunk

What you have at this point is a git repo that has all the SVN history. On my machine this actually takes up less space than the svn checkout

That is all well and good but you only have the snapshot of the trunk as of when I created the git repo.

At some point I will setup up an automated pull to keep history up to date, if you want to be able send a commit to the castle server you will need svn metadata anyway. To do that we use:

git svn init -T trunk -t tags -b branches

This will create a new .git/svn folder and add some options to your .git/config file.

Because we're doing things a little custom from the default behaviour of git-svn we need to edit this .git/config file to tell it where our subversion revisions go.

Open up .git/config in your favorite text editor and make the svn-remote section look like this


[svn-remote "svn"]
    url =
    fetch = trunk:refs/remotes/castle-svn/trunk
    branches = branches/*:refs/remotes/castle-svn/branches/*
    tags = tags/*:refs/remotes/castle-svn/tags/*

The stuff to the right of the equals sign is called a refspec and it tells git-svn that heads from svn under trunk goto refs/remotes/castle-svn/trunk (not the wildcard for branches and tags). This is creating remote-tracking branches in git.

With this in place you can now do git svn fetch and git will check your history against all the castle revisions. This does take a minute or so, but it is much faster than having to pull all the svn file data.

So now you want to work with RC3?

git checkout -b RC3 castle-svn/tags/1.0.x-RC3

What about the trunk?

git checkout -b trunk castle-svn/trunk

Maybe you need RC2

git checkout -b RC2 castle-svn/tags/1.0.x-RC2

Try switching between RC2 and RC3 and see how it compares to the paultry svn-switch.

In our next installment we'll look at fixing a bug and creating the patch.


PS: Trouble committing? Check here
PPS: My list of git resources so far

Published Oct 17 2007, 08:35 AM by chrisortman
Filed under: , ,



Jason Meridth said:

Great post Chris.  Thanks for the info.

October 17, 2007 10:19 AM

Chris Bilson said:

Hi Chris,

Thanks for this and the other post on git stuff. This is really valuable info.

I have a question about the castle tracking repository you made. I grabbed it (thanks!) and wanted to be able to track the castle svn repo, so I "git svn init ..." as shown above, but when I then "git svn fetch" after that, it takes forever, and looks like it is re-doing the whole svn --> git repo conversion. I killed it before letting it complete. I am experiencing the same thing with repos from my work that I converted and cloned to other machines.

Am I supposed to just track the mirror and not "git svn fetch" from my repo?

Thanks in advance if you can offer any advice!

December 4, 2007 3:41 AM

chrisortman said:

Hey Chris,

You might be running into a couple of different things.

First check wtih git log castle-svn/trunk just to make sure that when you cloned the git repo it wasn't like a week behind the castle svn repo.

If that's not the case then it will still take a few minutes when you run git svn fetch.

You should see lines like r2102 = 75892320392alkj23-alkja which is mapping each subversion revision to a git commit. This is normal, it is not pulling down new content just syncing up.

If you see a bunch of lines that look like output from svn log then git-svn is not looking in the right place in your repo for svn tracked branches.

So to check what's your output from git branch -r

mine is:


castle-svn/branches/ (insert arbitrary castle branch name here)


This is where git-svn needs to look for svn revisions and it is why I have the step to modify .git/config

If you look at the line

fetch = trunk:refs/remotes/castle-svn/trunk

that line tells git-svn that it should fetch trunk from svn and put the result in refs/remotes/castle-svn/trunk

As a test I just ran through the steps from my blog post and am now running git svn fetch. Total time was right at about 5 minutes.


December 6, 2007 6:14 PM

Leave a Comment

Powered by Community Server (Commercial Edition), by Telligent Systems