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.

7 thoughts on “Relocating git-svn checkouts

  1. The following might also work

    1)If svn-remote.svn.rewriteRoot does not exist in config file:
    git config svn-remote.svn.rewriteRoot

    2)If svn-remote.svn.rewriteUUID does not exist in config file:
    git config svn-remote.svn.rewriteUUID

    currentRepositoryUUID can be obtained from .git/svn/metadata

    3) git config svn-remote.svn.url

  2. If you misspell the new URL and run git svn fetch, you might find yourself in a situation where git svn fetch does nothing, no matter how often you change the URL and re-run git svn fetch.

    Took me like two hours to find the solution:

    Or in my case: rm -rf ./git/svn/refs/remotes/trunk/ && git svn fetch

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s