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.
- Install TortoiseGit
- Create a new folder where you want to clone the repository.
- Now right clock on the folder and select the “Git Clone …” option.
- You will see a clone screen. Choose “From SVN Repository” and uncheck all boxes.
- 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:
- Create a bare git repo using git init –bare
- Add this repo as remote to the SVN pulled repo.
- Push the SVN pulled repo to the git bare repo.
- 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.
11 thoughts on “Clone SVN repository to GIT using TortoiseGIT on Windows”
We’re u able to pull the branches too? If so can you please provide some details. Am able to get all the tags from svn. But not branches. Thanks.
I’m trying to Clone an SVN repository to GIT using TortoiseGIT on Windows following the instructions that you post.
I get the following error:
git.exe svn clone “svn://172.31.151.221:8080/bdg” “C:\Users\BDG\reposBDG\convertSVNtoGit\bdg”
svn: E235000: In file ‘subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c’ line 1666: assertion failed (get_current_pool_cb != NULL)
0 [main] perl 1354 cygwin_exception::open_stackdumpfile: Dumping stack trace to perl.exe.stackdump
I’m wondering if it is a version issue?
* git version 2.27.0.windows.1
* tortoiseGit 2.7.0
The only thing necessary to remove the SVN options (without re-cloning to another bare Git repo) is to go into the .git folder, edit the config file to remove the [svn …] options from the config and save, and then delete the svn folder that’s also inside of the .git folder.
OMG that was so useful, I was trying other command line tools with lots of incomplete conversions. Amazed by simplicity, thanks!
This really helps. iam successfully able to clone from SVN, Can you please help me on below questions.
I don’t see any .svn folder in cloned repo(GIT) from SVN, How ever i could see svn folder inside .git folder which is comprised of (caches,refs and .metadata).
Please suggest if i need to delete any folder from this cloned GIT repo(from SVN) before committing it to bitbucket. Also please do let me know if i need to consider any challenges while committing it to Bitbucket.
Please suggest if we can enable any sync mechanism from SVN to GIT.
Reblogged this on a record of a developer and commented:
This was useful to my interests
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?
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.
perfect. good article and help, thanks!
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!
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.