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
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.