The Wild

How to Migrate an SVN Repository to Git

· 6 min read · Mammals

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Migrating an SVN repository to Git preserves your full commit history, branches, and tags while giving you a modern, distributed version control system. This guide walks you through a clean, step-by-step conversion using git-svn, the most reliable tool for the job. Before starting, you'll need Git installed, SVN access to the repository, and a local copy of the SVN repo if it's not already on your machine.

What You'll Need

  • Git (version 2.x or later) installed on your local machine.
  • SVN client (optional but useful for verification) installed.
  • Access to the SVN repository – either a local path or a remote URL with read permissions.
  • A local directory where you'll perform the migration (e.g., ~/svn-migration).
  • An SVN authors file (optional but recommended) to map SVN usernames to Git names/emails.

Step-by-Step

  1. Create an authors file (recommended). SVN records only usernames (e.g., jsmith), but Git wants full names and emails. Create a text file (e.g., authors.txt) with lines like:
    jsmith = John Smith <john.smith@example.com>
    List every SVN user you want to map. If you skip this, you'll get generic placeholders like jsmith <jsmith@...>.
  2. Clone the SVN repository using git-svn. Run:
    git svn clone http://your-svn-server/repo --authors-file=authors.txt --trunk=/trunk --branches=/branches --tags=/tags
    If your repo uses a standard layout (trunk, branches, tags), you can simplify to:
    git svn clone http://your-svn-server/repo --authors-file=authors.txt --stdlayout
    This creates a new Git directory named after the repo. Be patient; it can take a while for large histories.
  3. Fetch any remaining revisions. If the clone was interrupted or new commits appeared, run git svn fetch inside the cloned directory to pull the latest changes.
  4. Clean up SVN-specific artifacts. Run git svn gc to optimize local references. Then, remove the SVN remote configuration with:
    git config --remove-section svn-remote.svn
    Also delete the .git/svn directory to fully detach from SVN: rm -rf .git/svn.
  5. Convert SVN tags and branches to proper Git refs. git-svn creates remote branches like remotes/origin/trunk and remotes/origin/tags/v1.0. Convert them to real Git branches and tags:
    git branch -r shows remote branches. For each tag (e.g., v1.0), create a Git tag:
    git tag v1.0 origin/tags/v1.0
    For each branch (e.g., feature-x), create a local branch:
    git branch feature-x origin/feature-x
    Then delete the temporary remote refs: git branch -r -d origin/trunk origin/tags/v1.0 origin/feature-x (repeat for all).
  6. Set the default branch to 'main' (optional). If you want to follow modern naming, rename the trunk branch (which is now your main branch, likely named trunk) to main:
    git branch -m trunk main (if your main branch is called trunk).
  7. Push to a remote Git hosting service. Create an empty repository on GitHub, GitLab, or Bitbucket. Then add it as a remote:
    git remote add origin https://github.com/yourname/your-repo.git
    Push all branches and tags:
    git push -u origin --all
    git push origin --tags
  8. Verify the migration. Check that the history looks correct with git log --oneline --graph. Compare a few recent commits against the SVN log to ensure nothing is missing.

Common Mistakes

  • Not using an authors file – results in ugly placeholder emails and makes history harder to read.
  • Forgetting to convert tags – if you skip step 5, tags remain as remote branches and won't be pushed as proper tags.
  • Cloning with the wrong layout – if your repo doesn't have a standard trunk/branches/tags structure, using --stdlayout will fail or produce an incomplete clone.
  • Pushing before cleaning SVN refs – you'll end up with extra remote branches like origin/trunk in your Git hosting.
  • Ignoring large files – SVN repos often contain binary files that bloat the Git history. Consider using Git LFS or excluding them if not needed.

Tips

  • Test on a local copy first. Clone the SVN repo to a local path (e.g., file:///path/to/repo) and practice the migration before touching the real remote.
  • Use a shallow clone for huge repos. If you only need recent history, add -r HEAD to the clone command to fetch only the latest revision. You can later deepen it with git svn fetch -r OLDER_REV if needed.
  • Keep the SVN repo untouched until you're confident. After migration, you can freeze SVN or switch to read-only.
  • Document the mapping. Save your authors file and the exact commands used, so you can reproduce or audit the migration.
  • Use a tool like svn2git for complex repos. If your SVN repo has unusual branching or many merges, svn2git (a wrapper around git-svn) can automate much of the cleanup.

Troubleshooting

  • Clone fails with "Unable to determine upstream SVN information". This usually means the layout doesn't match what you specified. Check the SVN repo structure with svn list http://server/repo and adjust the --trunk, --branches, and --tags paths.
  • History stops at a certain revision. This can happen if there are merge commits that git-svn can't handle. Try adding --follow-parent (it's often on by default) or use --no-metadata to simplify. If a specific revision is problematic, you can skip it with git svn fetch -r REV:HEAD --ignore-paths.
  • Tags appear as branches. This is normal after the initial clone. Follow step 5 to convert them properly.
  • Push fails due to large files. If the repo is huge, consider using Git LFS or splitting the repo. Alternatively, you can rewrite history with git filter-branch to remove large files, but do this carefully.
  • Commit dates are off. git-svn preserves SVN commit dates by default. If you see incorrect times, check your local timezone settings.

Frequently Asked Questions

Can I migrate without losing commit history?

Yes. The entire SVN history, including branches and tags, is preserved in the Git repository. The only loss might be SVN-specific metadata like revision numbers, but those are stored in commit messages by default (you can strip them with --no-metadata if you prefer).

What is the difference between git-svn and svn2git?

git-svn is a built-in Git command that does a straightforward conversion. svn2git is a third-party tool that automates the cleanup of branches and tags, making the result more Git-native. For simple repos, git-svn is enough; for complex ones, svn2git saves time.

Can I migrate a large SVN repository (e.g., 10,000+ commits)?

Yes, but it will take time and disk space. The clone process fetches every revision, so expect it to run for hours or even days for very large repos. Using a shallow clone first and then deepening can help.

What happens to SVN externals?

SVN externals are not automatically converted. You'll need to manually replace them with Git submodules or subtrees after migration. This is a manual step.

Do I need to keep the SVN repo after migration?

It's wise to keep it for a while as a backup, especially if you need to compare history. Once you're confident the Git repo is complete, you can archive or remove the SVN repo.

Can I migrate only a subdirectory of the SVN repo?

Yes, you can use --trunk=/path/to/subdir or use svn2git with exclude/include patterns. However, this will lose history outside that subdirectory, so make sure that's what you want.