Relocating git-svn checkouts

I use git-svn to maintain backups of our entire SVN repository. It’s fast, secure and easy; and the git clone of the whole repository history, branches and all uses about the same space as a subversion needs for a single revision, single branch checkout. No brainer.

Originally we used svn+ssh:// to provide remote SVN access. But as we’ve begun to collaborate with more and more people, we’ve needed to open up subtrees of our repository. And rather than creating user accounts for all these folk we’ve been giving them https:// access. This means that www-data needs to own the repository, so everyone needs to switch over to the new access scheme.

For regular svn checkouts that’s easy enough:

OLD_URL = `svn info; grep URL; cut -d" " -f2`
svn switch --relocate $OLD_URL $NEW_URL

Unfortunately git-svn has no equivalent sub command. Fear not. You could just clone from the new repository location, but that would be horribly wasteful. The following procedure (mainly cribbed from GitWiki) will see you right:

  1. Using svn checkout HEAD from the https:// repository. Cache your authentication credentials so git-svn can use them if necessary. This is important.
  2. If there haven’t been any commits since your last git-svn rebase make one now e.g. touch kick; svn add kick; svn commit -m "Kicking git-svn". This is important.
  3. Now, in your git-svn checkout edit .git/config. In the svn section, comment out the old url entry (hash or semicolon are valid) and add a new one.
  4. git-svn fetch to fetch a new revision from the new repository
  5. In .git/config comment out the new url entry and restore the old one.
  6. git-svn rebase -l to perform a local rebase
  7. In .git/config comment out the old url entry and restore the new one.
  8. Enjoy the fresh minty taste.