When trying to convert a SVN repository that contained all our projects, I couldn’t find a good solution on the internet on one page.

The most usefull pages were:

https://github.com/nirvdrum/svn2git

http://qugstart.com/blog/git-and-svn/migrate-an-svn-repository-to-git-while-maintaining-branches-and-tags-structure/

http://book.git-scm.com/4_tracking_branches.html

I combined them together and described the steps below that will get the job done.

sudo adduser git
nano /etc/group
git:x:100:usera,userb,userc
sudo mkdir /usr/local/git_root
sudo chown git.git /usr/local/git_root
sudo chmod 2770 /usr/local/git_root

Create authors.txt file for user mapping:

root = Root <root@example.local>
usera = My name <myname@example.local>

To get a listing of all users in the repository:

svn log file:///development/svn_projects | grep -E "r[0-9]+ \| .+ \|" | awk '{print $3}' | sort | uniq

Lets install Git, ruby and ruby gems now for the subversion 2 git conversion

sudo apt-get install git-core git-svn ruby rubygems
sudo gem install svn2git --source http://gemcutter.org
sudo ln -s /var/lib/gems/1.8/bin/svn2git /usr/bin/svn2git

Specify path to repository or an optional deeper path:

svn2git http://svn.example.com/path/to/repo(/project/foo) --authors /path/to/authors.txt

Create bare repository

mkdir /tmp/foo
cd /tmp/foo
sudo su - git
cd /usr/local/git_root/
umask 007
git clone --bare /tmp/foo foo.git
cd foo.git/

Make sure permissions are set properly

git config core.sharedrepository 1
git config receive.denynonfastforwards true
find objects -type d -exec chmod 02770 {} \;

The “core.sharedrepository” flag tells git to keep everything group readable and writable.
The “receive.denynonfastforwards” flag makes sure that merges can’t happen when you push to the repository.

You have to do the merges on your local machine, and then push the result.

The subversion repository is successfully converted to a bare GIT repository now!

Test it with a checkout:

git clone ssh://localhost:22/usr/local/git_root/foo.git

Optional:

Checkout tracking branch:

git checkout -b 2.x-dev refs/remotes/origin/2.x-dev

Nice commands:

git branch
git tag -l