How to Migrate from SVN to Git Without Losing History
Migrating from Subversion (SVN) to Git can seem daunting, but it’s a rewarding shift that brings better branching, speed, and a modern development workflow. In this guide, you’ll learn how to transition smoothly—whether you’re working on a legacy enterprise system or an open-source project.
Why Migrate from SVN to Git?
Subversion has served many teams well, but Git offers:
- Decentralized workflows
- Fast branching and merging
- Better performance
- Distributed collaboration
Git has become the industry standard, and migrating allows you to adopt modern CI/CD pipelines and work seamlessly with platforms like GitHub and GitLab.
🚧 Before You Begin
Ensure you have:
- The latest version of Git installed
- The
svn2git
tool (orgit svn
) - A clean SVN repository
- Backup of your SVN repo
On macOS:
brew install git svn
brew install svn2git
On Ubuntu/Debian:
sudo apt install git git-svn
Note: If your SVN repository uses custom layouts or has a lot of branches/tags, test in a staging area first.
🗺️ Step-by-Step Migration
Step 1: Understand Your SVN Layout
SVN repositories can vary. Common structure:
/trunk
/branches
/tags
But some may have /project/trunk
, etc. Knowing the structure is critical.
Step 2: Create a Local Git Repo
Create a clean directory and navigate into it:
mkdir my-git-repo && cd my-git-repo
Step 3: Clone Using git svn
(if not using svn2git)
git svn clone https://svn.example.com/repo --trunk=trunk --branches=branches --tags=tags --authors-file=authors.txt
If using a non-standard layout:
git svn clone https://svn.example.com/project --trunk=src/trunk --branches=src/branches --tags=src/tags --authors-file=authors.txt
📄 Sample authors.txt
jdoe = John Doe <john@example.com>
asmith = Alice Smith <alice@example.com>
Step 4: Or Use svn2git
(Easier for Standard Layouts)
svn2git https://svn.example.com/repo --authors ~/authors.txt --trunk trunk --branches branches --tags tags
Step 5: Clean Up Tags and Branches
SVN tags are often imported as branches. Convert them:
git for-each-ref refs/remotes/tags | while read ref; do
tag=$(basename "$ref")
git tag "$tag" "$ref"
git branch -D -r "tags/$tag"
done
Step 6: Push to a Remote Git Repository
git remote add origin https://github.com/youruser/new-repo.git
git push -u origin --all
git push origin --tags
🧼 Optional: Repository Cleanups
Remove SVN metadata:
rm -rf .git/svn
git gc --prune=now
Rewrite long commit messages, squash history, or restructure using:
git rebase -i
⚠️ Common Pitfalls
- Author mapping errors: Ensure
authors.txt
is accurate. - Large repos: Split them if necessary.
- Missing tags: Check branch/tag naming conventions in SVN.
🔄 Migrating a Team Workflow
SVN uses centralized commits; Git doesn’t. You’ll need to adapt:
- Teach contributors to fork and use pull requests
- Protect branches (e.g.,
main
,release
) - Establish Git workflows: Git Flow, trunk-based, or GitHub Flow
📊 Useful Tools
✅ Final Checklist
- All branches and tags migrated?
- Author map complete?
- History preserved?
- Clean repo structure?
- Git remote set up?
🚀 Wrapping Up
Migrating from SVN to Git is a one-time investment that unlocks better collaboration, workflows, and tooling. Plan carefully, test often, and don’t be afraid to start with a staging repo to refine your process.
Happy Git-ing!