How to migrate from SVN to GitHub in 7 steps
top of page

How to migrate from SVN to GitHub in 7 steps


migrate-from-SVN-to-GitHub

So, you've decided it's time to leave the old world of SVN behind and step into the modern realm of GitHub? Well, this guide is your trusty map to get you safely from SVN to point GitHub with all your precious commits, branches, and tags intact.


Step 1 - Checkout the SVN repository

Start by checking out the SVN repository using the following command:


svn co --username <your-svn-username> --password '<your-svn-password>' https://svn.example.com/path/to/repository


Step 2: Generate a list of commit authors

To map SVN commit authors to GitHub usernames, extract a list of all commit authors using this command:


svn log -q | awk -F '|' '/^r/ {gsub(/ /, "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt


This will create a list of all unique SVN commit authors in the format:


authorname = authorname <authorname@example.com>


Step 3: Map SVN authors to GitHub users

Manually edit the authors.txt file to map each SVN author to their corresponding GitHub username. For example:


janedoe = Jane Doe <janedoe@company.com>


Step 4: Clone the SVN repository as a Git repository

In a new directory, initialize a new Git repository with SVN history by running:


git svn clone -s https://svn.example.com/path/to/repository ProjectName --authors-file ../path/to/authors.txt --preserve-empty-dirs


Change https://svn.example.com/path/to/repository and ProjectName with your actual SVN URL and desired project name. The --preserve-empty-dirs option keeps empty directories from SVN in the Git clone.And just wait. This process can take quite a while…


Step 5: Manage branches and tags

  1. List branches: Once the SVN repository is cloned, navigate to the cloned repository and run: git branch -aYou will see all branches, including origin/trunk, which is equivalent to the main branch.

  2. Delete origin/trunk: Remove the unnecessary origin/trunk branch by running: git branch -d -r origin/trunk

  3. Rename master to main: If your repository still has a master branch, rename it to main: git branch -m master main

  4. Convert tags: If there are branches in the format remotes/origin/tags/tag1, convert them to actual Git tags by running:

    for t in `git branch -a | grep 'tags/' | sed s_remotes/origin/tags/__` ; do

    git tag $t origin/tags/$t

    git branch -d -r origin/tags/$t

    done


    Verify tags with: git tag -l

  5. Rename branches: For regular branches, run this command to rename them:


    for t in `git branch -r | sed s_origin/__` ; do

    git branch $t origin/$t  

    git branch -D -r origin/$t     

    done


  6. Confirm branches with: git branch -a


Step 6: Add the GitHub repository as a remote

Next, add the GitHub repository as the new remote:


git remote add origin git@github.com:<your-github-username>/<your-repo-name>.git


Change <your-github-username> and <your-repo-name> with your actual GitHub username and repository name.


Step 7: Push to GitHub

And finally, push all branches and tags to the new GitHub repository with:


git push --set-upstream --all origin


to push all the branches. And:


git push --tags


OPTIONAL: Handle large files

If there are large files in the repository, use Git LFS to manage them. Run this command to identify files larger than 59MB:


git lfs migrate info --everything --above=59MB


If there are files above this size, migrate them to Git LFS with:


git lfs migrate import --everything --above=59MB


Congratulations! You’ve successfully navigated the migration from SVN to GitHub. By following these steps, you’ve preserved your project’s history, organized branches and tags, and ensured that everything is now ready for the future in GitHub. Whether it was managing large files or renaming branches.



leonel-barragan



Leonel Barragan

Cloud Engineer

Teracloud

Buscar por tags
bottom of page