Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.


Stack Overflow

The old fashioned way


March 20, 2012 – 2:57am Import SVN project into Git

Recently we converted a few SVN projects to Git. We used a method that converts svn authors to git authors and then uploads the repository to github. It also maintains tags and branches. Here is how we did it:

echo "svnuser <>" > authors
mkdir myproject-git
cd myproject-git
git svn init -t tags -b branches -T trunk svn+ssh://svnuser@mysvnhost/path/to/svn/repo
git svn fetch --authors-file=../authors
git for-each-ref refs/remotes/tags --shell --format="r=%(refname:short) t=\${r#tags/}" | while read e; do eval "$e"; git tag -f $t refs/remotes/$r; git branch -d -r $r; done
git remote add origin
git push -u origin master
git push --tags

The git for-each-ref script was taken from and converts the tag branches into actual git tags and then delete those branches from the new git repository.

SVN externals will not be imported. In that event, you may find a git mirror of the svn repositories and you can set them up as submodules:

git submodule add git:// vendor/my-new-submodule
cd vendor/my-new-submodule
git checkout v1.0
cd ..
git add my-new-submodule
git commit -m "adding submodule at v1.0"
git push


If you need to find a specific svn revision number so you can tie your git submodule to the same revision, this will parse all of the git log messages (which will contain the svn revision number of it was imported from an svn repository) and display the revision numbers for you:

git log -z | tr '\n\0' ' \n' | sed 's/\(commit \S*\) .*git-svn-id: svn:[^@]*@\([0-9]*\) .*/\1 r\2/'


Posted by in  Web Development   |  

One Response to Import SVN project into Git

  1. ahoj says:

    git-svn doesn’t convert ignores and EOLs, unfortunately

    See my article about building a writable Git-SVN mirror
    (and of course SVN->Git or Git->SVN conversion is a particular case that can be solved by that approach)