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 http://repo.or.cz 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://repo.or.cz/castle.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 https://svn.castleproject.org/svn/castle -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
url = https://svn.castleproject.org/svn/castle
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 http://del.icio.us/chrisortman/git http://del.icio.us/chrisortman/git-svn