Importing Existing Git repository into SVN

Many of my colleagues know svn but are in general not (yet) ready jump over to using Git for bigger projects.

Today I had to import my existing Git repository into SVN. I had been working locally with a Git repos and wanted to keep my history before giving access to my colleagues.

The guide from Google Code is really easy, and the commands are just to follow (although several of them I don’t understand). Set the following variables to fit your needs

USERNAME=jesper
SVN_REPOS=https://project.caplab.dk/svn/
#NOTE in my example I expect standard /trunk, /tags, /branches layout
EXISTING_GIT_REPO=~/src/expensereport.git
NEW_GIT_SVN_REPO=~/src/expensereport


 $ git svn clone --username $USERNAME $SVN_REPOS $NEW_GIT_SVN_REPO
 $ cd $NEW_GIT_SVN_REPO
 $ git fetch $EXISTING_GIT_REPO

 $ git branch tmp $(cut -b-40 .git/FETCH_HEAD)
 $ git tag -a -m "Last fetch" last tmp

 $ INIT_COMMIT=$(git log tmp --pretty=format:%H | tail -1)
 $ git checkout $INIT_COMMIT .
 $ git commit -C $INIT_COMMIT

 $ git rebase master tmp
 $ git branch -M tmp master

$ git svn dcommit

Later, export Git repository updates to SVN as follows:


 $ git fetch $EXISTING_GIT_REPO
 $ git branch tmp $(cut -b-40 .git/FETCH_HEAD)
 $ git tag -a -m "Last fetch" newlast tmp
 $ git rebase --onto master last tmp
 $ git branch -M tmp master
 $ git svn dcommit
 $ mv .git/refs/tags/newlast .git/refs/tags/last

Find the full explanation from the Google Code wiki: ImportingFromGit
Import a Git repository to Google Code.

Found via Stackoverflow: Pushing an existing git repository to SVN

7 Responses to “Importing Existing Git repository into SVN”

  1.   links for 2009-07-08 by jonezy.org Says:

    […] justaddwater.dk | Importing Existing Git repository into SVN (tags: git sourcecontrol svn) […]

  2. Paul Nathan Says:

    Thanks jesper, for posting codes, i will also try em u

    I like the cool feature of SVN is the ability to branch (or take a copy of) your code – this allows you to keep, say, a development and a stable version. If you find a bug that needs patching in your production version, you can merge the change back in to the development branch thus avoiding regressions bugs. There are a number of version control systems out there, with subversion becoming one of the most popular in recent years. Recently though, git seems to be gaining some traction, especially amongst the Open Source community.

    Thanks bro for sharing it

  3. Sachin Gupta Says:

    Why are people moving to stone age? I love Git and the fact that I can have my own local repository and versions before ‘push’ing the changes to a common repository has made me a fan. I am glad these guys didn’t want to move to cvs :D

    I have used 4 popular version management systems in last 10 years including cvs, svn, rational clear tool and git and except the cool GUI merging that cleartool had nothing will move me from git :D

  4. NesMedya Haber Video Oyun Seo Yarışması Says:

    I like the cool feature of SVN is the ability to branch Open Source a development community.

  5. markus Says:

    i was having the problems related to the SVN & then i was trying to get the help of my coder but now i would like to show your post that guy!

  6. Robert Says:

    I’m staying with Git. Other than the ability to branch your code to keep multiple versions, I see little reason to move to SVN. Plus I’ve heard that converting your code can be a nightmare even with the Google guide.

  7. Janelle Bailey Says:

    “Many of my colleagues know svn but are in general not (yet) ready jump over to using Git for bigger projects.” I can relate to your colleagues. I also know svn but I admit that I do not use Git for bigger projects simply because I am not ready for it and I am not that familiar in using it.