Tag Archives: git

Bash script to migrate from SVN to git

At work we took the decision to switch from the good old SVN to git. To ease all the work, I wrote a small bash script that takes 2 arguments, the SVN repository name and the git repository name and moves your code cleanly to git.
It also requires a file users.txt that is located in the same folder as the script which has the following layout (1 user per line).

meredrica = Florian Westreicher 

The file is needed to map the SVN users (meredrica in this case) to the git users.

And finally, here’s the script. Make sure you change the svn/git urls before running it.

#!/bin/bash
PROJECT=$1
GIT=$2
mkdir temp
cd temp
/usr/bin/git svn init http://localhost/svn/$PROJECT --no-metadata
/usr/bin/git config svn.authorsfile ../users.txt
/usr/bin/git svn fetch
cd ..
mkdir $PROJECT
/usr/bin/git clone temp $PROJECT
rm -rf temp
cd $PROJECT
/usr/bin/git push ssh://git@localhost/$GIT.git master
exit 0

Thanks go to Jon Maddox for his guide over at his blog

Switch to our mobile site