SmexyyWeby

Scripting for Fun and Passion

Clone SVN repository to GIT using TortoiseGIT on Windows


I enjoy using git because of its simplicity and speed. Recently, I have been working on a project of ours which uses SVN as a default version control system.

I proposed to my team to switch to Git as we can also use GitHub after that for making our code public. So, I decided to take the initiative to convert our SVN repository ready for GIT. There were 2 solutions to this:

  • I use the latest stable code and then check it into the latest GitHub repository.
  • I convert the whole SVN repository into Git repository.

I wanted to do the latter as I want to ensure that the commit logs are maintained across the clone.

So, after looking on the internet I found a few solutions using git-svn. The github site gives a good link on how to do it on a linux machine: https://help.github.com/articles/importing-from-subversion

However, I was looking for some Windows based solution which is easy to use and GUI based as I have to show it to my team as well. So, I decided to use TortoiseGIT [https://code.google.com/p/tortoisegit/wiki/Download?tm=2] which is a Windows based tool for git repositories.

Here are the steps I used using tortoiseGit to clone my SVN repository as a Git repository.

  1. Install TortoiseGit
  2. Create a new folder where you want to clone the repository.
  3. Now right clock on the folder and select the “Git Clone …” option.
  4. You will see a clone screen. Choose “From SVN Repository” and uncheck all boxes.Image
  5. Click OK.

It will take some time depending on your SVN repository size but in the end you will be presented with a Git repository in your folder.

One problem which you will face is that now in the tortoiseGIT menu you will see SVN options as well.

In order to remove that the following steps provide a solution:

  1. Create a bare git repo using git init –bare
  2. Add this repo as remote to the SVN pulled repo.
  3. Push the SVN pulled repo to the git bare repo.
  4. Now clone the bare git repo to a new repo.

New repo will not have SVN options.

Using git-hooks to update the cloned repo when the bare repo is updated.

Inside hooks folder in the bare repo create a file post-receive

Add the following content to the post-receive file

#!/bin/sh
cd /home/<user>/<test_repo>
GIT_DIR=.git git pull origin master

Now whenever you push something to the bare-repo then the changes are already reflected in the git repo whose path is given in post-receive file.

Advertisements

6 responses to “Clone SVN repository to GIT using TortoiseGIT on Windows

  1. frostfang83 July 3, 2015 at 12:37 pm

    Reblogged this on a record of a developer and commented:

    This was useful to my interests

  2. mlawson July 24, 2014 at 11:49 pm

    OK, well i’m just trying to move from SVN to GIT, i no longer need the repo to be accessible via SVN. So after I clone from SVN I should just be able to commit it to a git repo correct?

    • NapsterNXG July 25, 2014 at 10:49 pm

      Ya that will work. Infact if you want to remove the SVN part of it all together after moving to git then all you can do is simply delete the “.svn ” folder in your repository and that will take away the SVN context menu as well. Once you convert to GIT you will have 2 folders “.svn” and “.git” make sure the “.git” folder is still there.

  3. mlawson July 23, 2014 at 2:17 am

    I followed your first part of instructions just fine and it successfully created the git repo, but could you please provide more detail about the 2nd part of the instructions regarding removing the SVN options? how do i perform each step? thanks!

    • NapsterNXG July 24, 2014 at 4:00 am

      Hi mlawson,
      The issue I am discussing is that when you create the git repo it resides in the same directory as the SVN repo. I would personally in this situation would want to abandon the SVN repo and work only using GIT. Or if you want to keep a copy of the SVN repo and work with the GIT repo in another folder then you can use the 2nd part. It is not necessary but useful.

      In the steps what I basically mean is you can create an empty bare repo of git which is a repo on which you don’t work but acts like a main repo from which everyone can fork. Now you can make this repo a remote for the git repo you got from the SVN. in this bare repo you can push the code of the GIT repo. And then you can basically clone the bare repo to some other folder and work in that copy to keep the SVN and the GIT version separate.

      Using this technique your team can continue using git as well as SVN. The people working in SVN can work on the SVN branch and the ones working on the git branch and push to the remote which can be used to updated the SVN branch.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: