Migrate From SVN to GIT

The goal of this how-to is to convert the source Subversion repository to a local bare Git repository.

This section provides all the information concerning the migration from svn to git
The information communicated is about a test scenario with screenshots and main steps.


In order to perform this operation, it is essential to have the following prerequisites:

  • Version git> 2.1.0 (here, we use version 2.12.0)
  • An account activated on the svn repot.
  • Svn (it is recommended to look for a version close to 1.9.5)

Let’s suppose we have the svn repot address as:

Note that the user keyword in the path refers to the current svn user authenticated.

In general, each SVN repository has the structure bellow

In our case, we will recover only the codes in the Trunk folder because there are no more tags or branches.


In the demo suite, I will consider my project folder as the root folder with the annotation

  • Move to the folder
$ cd path/to/folder
  • Create a folder in which you will recover the code with svn and move inside
$ mkdir my-project 
$ cd my-project
  • Download the project in this folder
$ svn co

If this is the first time, a password and identifier is required to access the repos.

This step take several moments, Wait until the data download is finished, Check the data recovery.

Generate the authors.txt file by moving to the trunk folder

$ cd project/trunk
  • Run the bellow command
$ svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "",   $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

A nammed files authors.txt will be generated as :

user = user <user>

Remember to put the final address, the nickname you use on your git server instead of the one below.

chabli = chabli yassine <chablimohammedyassine@gmail.com>

Save this file because we will come back for use in the next steps.

Move to the folder Create a new folder named as you want:

$ cd my-project
$ mkdir git-from-svn-repos
$ cd git-from-svn-repos
$ cp ../project/trunk/authors.txt ~/ (copy the authors.txt file in the new folder )

Now we will make configurations on the git side, these are the configurations for the account used by the one who will commit in the git repository.

Fill in the information: user.name, user.email, svnauthorsfile

$ git config --global user.name "yassine chabli"
$ git config --global user.email "chablimohammedyassine@gmail.com"
$ git config --global user.authorsfile path/to/git-from-svn-repos/authors.txt
  • Check the configuration list
git config --list

Move to git-from-svn-repos

$ cd git-from-svn-repos

And finally , launch the magic git command

$ git svn init --stdlayout --username chabli

This step consists of creating the .git configuration folder.

Git configuration customization

Before recovering the files, you must make a modification in the config file of git.

$ cd .git

Let’s edit the config file.

	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[svn-remote "svn"]
	url =
	fetch = :refs/remotes/git-svn 
	branches = trunk/branches/*:refs/remotes/origin/*
	tags = trunk/tags/*:refs/remotes/origin/tags/*
[remote "origin"]
	url = https://github.com/yassinechabli/ariatalend.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

Normally, when you check the file, you will find a different valuation to this one for the attribute fetch. Remember to change the whole line by :refs/remotes/git-svn for fetch attribute.

Go back to the git-from-svn-repos folder and then execute the command

$ git svn fetch

Wait until data recovery is finished.
At this point, the main task is done, just commit the code to your git server.

$ git remote -v // this must show nothing
$ git branch // you must see the master branch 

Let’s add the remote and push it .

$ git remote add origin link_to_repos
$ git push -u origin master

This step takes a few moments depending on the size of the project.