Sunday, September 25, 2011

Git-SVN Mirror without the annoying update-ref

This post is part of a series on Git and Subversion. To see all the related posts, screencasts and other resources, please click here

So no sooner than I had done my git-svn presentation at JavaZone, I got word of a slightly different Git-SVN mirror setup that makes it a bit easier to work with:

In short, my old recipe includes an annoying git update-ref step to keep the git-svn remote reference up to date with the central bare git repo. This new recipe avoids this, so we can simply use git svn dcommit  directly.

So, longer version, with the details. My original recipe is laid out in five steps:

  1. Clone a fresh Git repo from Subversion. This will be our fetching repo.
  2. Set up a bare repo.
  3. Configure pushing from the fetching repo to bare repo
  4. In the shoes of a developer, clone the repo
  5. Set up an SVN remote in the developer's repo
In the new approach, we redefine those last two steps:

(See the original post for how to do the first three.)

4. Clone the bare repo

Note the -o parameter that specifies that we want to call the origin remote "mirror":

tfnico@flint:~/sources/git/>git clone -o mirror ~/git-repos/websites.git/

We can now track the remote branches, and pull the latest changes as they come in to the bare repo.

tfnico@flint:~/sources/git/websites/>git checkout -t mirror/yksi
tfnico@flint:~/sources/git/websites/>git pull --rebase

(Remember to use --rebase to avoid merge commits in case you have local commits.)

When the time comes to push commits back to Subversion, we have to complete the last step.

5. Set up an SVN remote in the developer's repo

We'll do an svn-init with the same parameters as we cloned in the beginning, adding a prefix that matches the name of the remote "mirror":

tfnico@flint:~/sources/git/websites/>git svn init --prefix=mirror/ -s file:///svn-repos/company-repo/websites/

The point of the mirror/ prefix is that whenever we do a pull, the git-svn reference will be updated along with the normal remote reference. So now you can do git svn dcommit without any further ado.

Friday, September 09, 2011

My JavZone git+svn talk is online

This post is part of a series on Git and Subversion. To see all the related posts, screencasts and other resources, please click here

Update: I've also shared my notes from the talk. Here they are.

So, the Cisco/JavaZone folks were lightning fast and uploaded the recording of my session at JavaZone the day after I held it. Here it is:

You'll have to watch it fullscreen and in HD to follow the command line action, I reckon.

I think this marks the climax, and probably the end of my adventures with git+svn. I mean, we're still using it at work, and I'll still help people with it when they ask on the "Git for human beings" mailing list. However, I won't submit it to any more conferences or user group meetings.

It's been a really interesting topic, and an important one. The resources-page has gotten 6000 views (plus a lot more on the blog posts), and the screencasts on YouTube have received nearly 4000 views. It's been adopted by at least one open source project, two companies where I set it up, and I've seen some incoming links from some big companies' intranets. I still hope more people will find them and make use of the knowledge.

One problem is that if you google "git svn", my resource page is nowhere near the first page. The top results are littered with typically 3-4 year old posts with really trivial git-svn stuff. So if you want to help others find this stuff, you can help out by linking to it like this:

Check out this git svn page!
So, google-bomb away :)