Linux, tip, Tools

Moving SVN repo’s to GIT

We have a lot of legacy code in our SVN server, and over the last couple of weeks i’ve been migrating all the old repos to GIT.

Its hasn’t been overly straight forwards luckily I found some great tutorials online,

and also these have been really useful on try to figure out how to merge two GIT repositories

Eventually I turned John Albin’s method into a bash script to make the process fairly automated see the Gist below


# based on with a some tweeks
# (NB: its quick and dirty, has no error checking and only works on repos structured with a stdlayout i.e. a trunk folder)
# use:
# $:./ new-repo-name http://user@server/repo/


cd ~/

# Create a Bare Repository
git init --bare ~/$BARE_REPO_NAME.git
cd ~/$BARE_REPO_NAME.git
git symbolic-ref HEAD refs/heads/trunk

# Clone the Subversion repository using git-svn
cd ~/
git svn clone $SVN_PATH --no-metadata -A authors-transform.txt --stdlayout ~/temp

# Convert svn:ignore properties to .gitignore
cd ~/temp
git svn show-ignore > .gitignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'

# Push repository to a bare git repository
git remote add bare ~/$BARE_REPO_NAME.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare

# Rename “trunk” branch to “master”
cd ~/$BARE_REPO_NAME.git
git branch -m trunk master
rm -rf ~/temp

# Clean up branches and tags
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";