Getting started with Git and GitHub and importing from Subversion

If you’re working an open-source projects, these days you can barely get around Git and GitHub. Actually getting started, especially on Windows, isn’t trivial. In my case I had some projects I need to transfer from a Google Code subversion repository to a new repository at GitHub. Actually getting started with GitHub needs to wait for another post, but here are some commands for importing from Subversion:

git svn clone http://[yourproject].googlecode.com/svn/trunk/path/to/code/
git remote add origin [email protected]:[youraccount]/[yourrepository].git
git push origin master

This will create a new folder, based on the svn url you provide (the last part will provide the folder name) and get the files from that path, including the history(!). The second command tells the local Git repository where the next command should go to. You have to replace that URL with “Your clone URL” from your GitHub project.
The last command actually pushes the code to the repository. For that to work, the GitHub repository should be brand-new and empty. If you tried GitHub’s SVN import and got nothing, the repository may be filled with something that GitHub doesn’t show. In that case, create a new repository and import into that. You can remove/delete later.

The following code should do mostly the same, but instead of creating a folder, will initialize an empty repository in the current folder, then do the checkout from svn into that folder (need to test that again):

git init
git svn clone http://[yourproject].googlecode.com/svn/trunk/path/to/code/ .
git remote add origin [email protected]:[youraccount]/[yourrepository].git
git push origin master

Note the dot after the svn clone command.

Thanks to Kelvin Luck for the ideas and commands!

-Jörn

No more comments.
  1. Paul McLanahan

    I’m glad to see jQuery and the associated projects move to DVCS, but I was hoping for Mercurial 🙂 I find it much easier to use, and it’s windows support is vastly superior since it’s mostly written in Python. It’s also very easily extensible with Python. If you haven’t checked out Mercurial, give bitbucket.org a try. It’s a lot like GitHub, but for Mercurial.

  2. On the web there are billions of SVN2GIT guides but I love when them are so simple.

    I’m considering to move my SVN repos to git and thanks to you it is clear how now I need to understand why 😛

    Thanks

  3. I’ve moved a few of my projects from SVN to github and it was seriously a breeze! Thanks for posting some useful tidbits like this – it’ll help a lot of people with the migration.

  4. I tried this with importing a wordpress plugin from their SVN repo to a git repo, but wordpress.org seems to have ALL their plugins in one repo, hence git tries to import it all. I have found no easy way to import a “sub section” of an svn repo. SVN allows you to checkout just the subdir from the repo 🙁

  5. @Lantrix: Just specify the same path you use for checkout in the “git svn clone” command.