How Do I Migrate an Svn Repository with History to a New Git Repository?

Better Stack Team
Updated on July 25, 2024

Migrating an SVN repository with its complete history to a new Git repository involves several steps. Here’s a comprehensive guide on how to accomplish this migration:

Prerequisites

  1. Install Git and SVN: Ensure Git and SVN are installed on your system. You can download Git from git-scm.com and SVN from subversion.apache.org.
  2. SVN Repository Access: Have access to the SVN repository URL and credentials, if required.

Step-by-Step Migration Process

1. Initialize a New Git Repository

Create a new Git repository where your SVN history will be migrated to:

 
mkdir new-git-repo
cd new-git-repo
git init

2. Install git-svn (if not already installed)

If you haven't installed git-svn, you'll need it to interact with SVN repositories from Git:

 
# On Debian/Ubuntu
sudo apt-get install git-svn

# On macOS (with Homebrew)
brew install git-svn

# On Windows (with Git for Windows)
# git-svn is typically included in the installation package

3. Clone SVN Repository with git-svn

Use git svn clone to clone the SVN repository into your local Git repository. This command will fetch all SVN history and convert it into Git commits:

 
git svn clone <SVN-repo-URL> --no-metadata -s
  • <SVN-repo-URL> should be replaced with the URL of your SVN repository.
  • -no-metadata ensures that Git does not create additional SVN-specific metadata branches in your Git repository.
  • s assumes a standard layout (trunk, branches/*, tags/*) for SVN repositories. Adjust flags as necessary if your SVN repository has a different structure.

4. Verify the Migration

Once git svn clone completes, you'll have your SVN repository history migrated to Git. Verify the commits and structure:

 
git log --oneline

This command will display the commit history from the SVN repository converted into Git commits.

5. Push to a New Remote Repository (Optional)

If you want to push your migrated Git repository to a remote Git repository (like GitHub, GitLab, etc.), create an empty repository on the remote platform and push your local repository to it:

 
git remote add origin <remote-repo-url>
git push -u origin master

Replace <remote-repo-url> with the URL of your remote Git repository.

Additional Considerations

  • Branches and Tags: Ensure that all branches and tags from your SVN repository are correctly mapped to Git branches and tags during the migration.
  • Large Repositories: For large SVN repositories, the migration process may take significant time and disk space.
  • Adjustments: Depending on your SVN repository structure and history, you may need to adjust the git svn clone command flags or perform additional steps.

By following these steps, you can successfully migrate an SVN repository, including its complete history, to a new Git repository. This process preserves commit history and allows you to continue development using Git's version control system.

Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github