Tibor's Musings

Git Subversion Mirroring

Consider a project using git source code management system. Now imagine a need arises to automatically mirror git commits to a (read-only) subversion repository. How can one achieve such an automated push?

One technique is to use git-svn extension and prepare git grafts to link the two repositories together. Here is a functional example demonstrating the concept:

## prepare test space:
rm -rf /tmp/test-git-to-svn
mkdir -p /tmp/test-git-to-svn
cd /tmp/test-git-to-svn

## create test git project:
mkdir test-project-git
cd test-project-git
git init
echo a > README
git add README
git commit -a -m a --author='Erika Mustermann <erika.mustermann@example.org>'
echo b > README
git commit -a -m b --author='John Doe <john.doe@example.org>'
git log
cd ..

## create test SVN repo and its structure:
svnadmin create test-svn-repo
svn co file:///tmp/test-git-to-svn/test-svn-repo work-svn-repo
cd work-svn-repo
svn mkdir trunk tags branches
svn commit -m "initial repo structure"
cd ..

## make test SVN checkout:
svn co file:///tmp/test-git-to-svn/test-svn-repo/trunk test-1
cd test-1
svn log
cd ..

## link SVN repo to Git repo:
cd test-project-git
git svn init -s file:///tmp/test-git-to-svn/test-svn-repo
git svn fetch
git branch -a

## prepare git graft:
A=`git show-ref trunk | awk '{print $1;}'`
B=`git log --pretty=oneline master | tail -n1 | awk '{print $1;}'`
echo $A
echo $B
echo "$B $A" >> .git/info/grafts

## now try first commit:
git svn dcommit

## test new checkout from SVN:
cd ..
svn co file:///tmp/test-git-to-svn/test-svn-repo/trunk test-2
cd test-2
svn log
cd ..

## now emulate more work in git:
cd test-project-git
echo c > README
git commit -a -m c
git svn dcommit

## now try SVN update:
cd ..
cd test-1
svn up
svn log

git