2011-05-29

git with multiple svn-remotes

Use git init to create an empty git repository, then edit .git/config to add the svn remotes:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[svn-remote "svn"]
url = file:///home/steve/code/svn-repos/foo
fetch = trunk:refs/remotes/trunk
branches = branches/*:refs/remotes/*
tags = tags/*:refs/remotes/tags/*
[svn-remote "svn-other"]
url = file:///home/steve/tmp/foo-svn-other
fetch = trunk:refs/remotes/svn-other/trunk
branches = branches/*:refs/remotes/svn-other/*
tags = tags/*:refs/remotes/svn-other/tags/*

It is assumed at this point svn-other is simply a copy of svn. They are allowed to diverge later.

Do a git svn fetch -R svn to initialise git svn. To manage commits between the two svn remotes, create local tracking branches of remote branches:

$ git checkout -b trunk-other remotes/svn-other/trunk

I ended up with something like :

  master
  trunk
* trunk-other
  remotes/svn-other/trunk
  remotes/trunk

You can pull changes from one svn repository then push it to another:

$ git svn fetch -R svn
r1 = 049fed636e283096986e0eefa261be0525d8d7b3 (refs/remotes/trunk)
Checked out HEAD:
$ git svn dcommit
Committing to file:///home/steve/tmp/foo-svn-other/trunk ...
A test
Committed r2
A test
r2 = 10613af6701eca4b30a3ff89ab408e38ca157fa0 (refs/remotes/svn-other/trunk)
No changes between current HEAD and refs/remotes/svn-other/trunk
Resetting to the latest refs/remotes/svn-other/trunk

Cheers,
Steve