Are you already in love with Git? I’m pretty sure of that, that’s the reason why you are reading this, huh?

These are the steps you should follow to migrate an existing SVN repository to a Git one:

1 – Create a file where you will map SVN users to Git users, following this pattern:

svn_user = git_user

This is the one I created to migrate some SVN repositories from Google Code:

$ cat authors_mapping_googlecode
dpecos = Daniel Pecos Martinez
(no author) = Daniel Pecos Martinez 

The author (no author) is required to match some commits made by Google in the SVN repository creation process.

2 – Now let’s import code from SVN:

git svn clone --username svn_user --authors-file=authors_mapping --no-metadata -s svn_url git_repo_path_tmp

The one I used to import my np-lib project was:

git svn clone --username dpecos --authors-file=authors_mapping_googlecode --no-metadata -s np-lib_tmp

We can go into the just created Git repository and display its log in a pretty tree format:

$ git log --graph --decorate --pretty=oneline --abbrev-commit

3 – Next step is to clone this repository into a new one, just get ride of all SVN junk created by git-svn:

$ git clone git_repo_path_tmp git_repo_path<br /> $ rm -rf git_repo_path_tmp<br /> $ cd git_repo_path<br /> $ git remote rm origin

4 – We are ready, but maybe you want to push your repository to GitHub (or any other one), so what you’ll need to do as follows:

(At this point I suppose that you have created a Git repository in GitHub and that you have already setup your environment to push content to it, if not, you will have troubles from now on)

$ git remote add remote_name git_url

In my case it was:

$ git remote add github

Some clarifications about this last command: many people use as default remote Git repository name “origin“, me too, but in this case, GitHub wasn’t my default remote Git repository, but I private one so I decided to create a “github” remote.

Now we only have to push local content to the remote repository:

$ git push remote_name master

Which in my case was:

$ git push github master

And that’s all, we got a Git repository set up and ready to work with GitHub starting from a SVN one.

Hope this recipe will help you. Time to enjoy!