Migrating from a Subversion repository to GitHub

I’ve just moved a SVN repository to github. I was a bit afraid of spending time and lost the history but fortunately, I came upon this great post http://www.samaxes.com/2013/11/move-from-svn-to-git/ , followed the instructions and it worked almost like a charm.

Here is a summary of the instructions but please visit the original post if you want to understand what you are doing. The following being just a recipe rather than a thorough explanation of what is going on behind each instructions.

Let us assume that the name of the SVN repository is MYPROJECT and you have it locally in SVNDIR and that you will name it on github with the same name MYPROJECT.

First, we need to figure out the names of the contributors in the SVN directory and their respective names in the github repository:

 cd SVNDIR
svn log --xml | grep -P "^<author" | sort -u | perl -pe 's/&lt;author&gt;(.*?)&lt;\/author&gt;/$1 = /' &gt; authors.txt

edit the authors.txt to add the github author names. Keep it safe. We will use it later on. The format looks like

svnuser1 = Firstname Surname <email>

Note that you may have a svnuser called www-data. I kept it but put my firstname/surnma/email to replace it in the new git repo.

Now, let us copy the SVN into a new directory and make sure this new directory is cleaned up from useless files. We can do that by just cloning the SVN repository using git itself:

  cd ~/TEMP 
  git svn clone https://subversion.assembla.com/svn/MYPROJECT --no-metadata --stdlayout --authors-file=authors.txt MYPROJECT
 cd MYPROJECT

If you end up with a

git: 'svn' is not a git command. See 'git --help'.

just install git-svn tool, which is probably missing on your system.

Here of course, you need to provide the proper svn repository. To obtain that information type svn info in your SVNDIR directory. The file authors.txt is the one created earlier.

Note here, that you will get everything (trunk/tags/branches) and the following code will clean up things for you so you end up with a
proper gitbuh repository

 git for-each-ref refs/remotes/tags | cut -d / -f 4- | grep -v @ | while read tagname; do git tag "$tagname" "tags/$tagname"; git branch -r -d "tags/$tagname"; done
 
 git for-each-ref refs/remotes | cut -d / -f 3- | grep -v @ | while read branchname; do git branch "$branchname" "refs/remotes/$branchname"; git branch -r -d "$branchname"; done

Before going to the next steps, do not forget to ceate the MYPROJET repository on github itself !!

The next step took me a while to understand. In the original post,

 git remote add origin git@my-git-server:myrepository.git

I thought I had to do the following replacements:

  • git by my username but no ! keep it as it is.
  • my-git-server is github.com, which is correct
  • myrepository.git by MYPROJECT but no, it should be USERNAME/MYPROJECT

So, just type something like that shoul work:

  git remote add origin git@github.com:USERNAME/MYPROJECT
  git push origin --all -v

I also had issues with permission at that stage. The following command helped me somehow to figure out it was a SSH key missing on github

    ssh -vT git@github.com
    ssh-add -l

Hoping this helps.

References:

  • https://help.github.com/articles/generating-ssh-keys
  • http://www.samaxes.com/2013/11/move-from-svn-to-git/
  • http://imakewebthings.com/blog/github-pages-email/
  • https://help.github.com/articles/error-repository-not-found
Please follow and like us:
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *