Skip to content


Using svn and git concurrently

June 12, 2010

I have used git at work for my local development for quite a time. In our network we have a subversion server for collaboration, so that I used git-svn locally. Now I wanted to publish an open source project and came to the idea to use github for the first time. After first commits I noticed that the commit messages apparently hold the git-svn information, that is the reference to the revision. That is the result of that I want to use our internal svn and github concurrently.

My solution to use my local svn backend and use the git master branch in the normal way, is to branch the svn and work with rebasing and cherry-picks, to not confuse the world with my internal svn stuff. This is a quite simple solution, but maybe helps you to solve the same issue.

First you need to branch from your current master HEAD.

git branch svn
git checkout svn

Initialize SVN from git

Initially we want to push our current stuff to the subversion repository. This is not absolutely straight forward, but easily done as described here.

git svn init http://url/to/svn
git svn fetch
echo `git log --pretty=oneline master | tail -n1 | awk '{print $1}'` `git show-ref git-svn | awk '{print $1}'` >> .git/info/grafts

Now we can commit the current git to the subversion server

git svn dcommit

Push stuff to SVN

Pushing stuff to svn is pretty straight-forward as a series of commands, that can e.g., be put in an alias:

git stash
git checkout svn
git rebase master
git svn rebase
git svn dcommit
git checkout master
git stash apply

Get stuff from SVN

This part is kinda ugly, because we need to rewrite IDs. The best efficient way I found so far is manual, but I hope I can elaborate an automated way for it.

First get the current revision from SVN.

git checkout svn
git svn rebase

Now some comparison work is required, because you will need to get the revisions one per one and rewrite the commit messages. First check the log in the svn branch

git log

You will see the new revision. Now we will pick this one also for our git master branch, so that we first switch there:

git checkout master

and now pick the commit by the id in svn branch

git cherry-pick commit-id

Now we still need to rewrite the comment, that can be done by amending the last commit

git commit --amend

will open the editor and let you remove the git-svn-id line.

This may not be the best way to do it, but I hope it helps you with such a layout.


From → Uncategorized

  1. Trying to follow your instructions… fail on the first “git svn dcommit” saying:

    % git svn dcommit
    Unable to determine upstream SVN information from HEAD history.
    Perhaps the repository is empty. at /usr/lib/git-core/git-svn line 780.

    The git repo has a lot of history which I’m trying to publish to a new stdlayout dir in a centralized svn repo with a lot of other projects and history.

    Any idea of what could be wrong?

    • Hi Pablo,

      this sounds a bit odd. What is the content of the grafts file?


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

%d bloggers like this: