Photo by Markus Winkler on Unsplash

Migrating an SVN Repository to Github

Techstacks change! And so do the tools we use. As with most changes, there is the issue of migration of existing data to a newer platform. E.g., if your repository was on SVN and now you want to move to Github, then how to go about it.

SVN v/s Git used to be hotly debated. In recent years though, Git is the clear winner. So chances are, if you are on SVN, you’d be moving to Git, and probably Github, pretty soon.


Recently I needed to migrate an SVN repository to Github. There are two significant steps involved in this process:

  1. Migrate SVN repository to a local Git repository
  2. Push local Git repository to Github

1. Migrate SVN Repository to a Local Git Repository

1.1. Retrieve a list of all Subversion committers

$ svn log -q [SVN repo URL] | \
awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); \
print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

This command will fetch all the log messages, extract and sort the distinct usernames, and place them into an authors-transform.txt file. Now change

username = username <username>

into this:

username = Firstname Lastname <>

for the mapping between corresponding SVN and Git users.

1.2. Clone the SVN repository using git-svn

git svn clone [SVN repo URL] --no-metadata -A authors-transform.txt --stdlayout ~/temp

This command may take a while, depending on the size of SVN commit history. Once completed, check if the SVN commit history has been migrated correctly by running git status and git log inside directory~/temp.

1.3. (Optional) Convert svn:ignore properties to .gitignore

If your svn repo was using svn: ignore properties, you can easily convert this to a .gitignore file using:

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

2. Push Local Git Repository to Github

2.1. Create a new repository in Github

Make sure the project is empty i.e., no Readme or License. Copy the .git URL, e.g.<username>/<reponame>.git.

2.2. Set remote repository for the local repository

git remote add origin<username>/<reponame>.git

2.3. Push local repository to remote

If the remote project is empty with no log, the following command should cleanly push the code to Github repository

git push -u origin master

However, if the Github project has any record, you may run the following command to merge the logs:

git pull --allow-unrelated-histories  origin master
git push -u origin master

That’s it!




Product engineering to solve business problems

Recommended from Medium

Cloud-printing for Restaurants with AWS IoT Greengrass

Obtain GeoTIFF with ASCII files

Snowflake Python Series 2: Setting Session Parameters using .env File

Anaconda Installation guide on Windows for Data Science

Best Open Source Frameworks for Web Scraping

1 sprint hackathon in a 6 sprint PI for SAFe practicing organizations

Calculus, a different perspective

Scottie Pippen and Bootstrap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brajesh Sachan

Brajesh Sachan

engineer, entrepreneur

More from Medium

Odoo and ERP Next a Micro Comparison

DrChrono EHR and API For Developers

DrChrono EHR Software

Everything You Need to Know About DevOps

Importing Data into AWS RDS MSSQL from S3 using SQL and SSIS