Migrating to Git From Subversion, TFVC and Mercurial
Move a project to Git from another version control system: full history or a fresh start, mapping authors, converting Subversion with git svn or svn-all-fast-export, TFVC with git-tfs, Mercurial with hg-fast-export, the fast-import format behind them, verifying the result, and switching the team.
kvi5hnuCode Sprout team member9 min readOn this page
Many teams arrive at Git from an older system: Subversion (SVN), Team Foundation Version Control (TFVC), Mercurial, or Perforce. Converting the code is usually the easy part. The work is in deciding how much history to keep, mapping usernames to real identities, turning the old branch and tag layout into Git branches and tags, and helping people change habits. This article covers the decisions, the tools for each system, and how to check the result.
Decide first: full history or a fresh start?
| Approach | How | Good when |
|---|---|---|
| Full history | convert every revision, branch and tag | history is used for blame, audits or bisecting, and is reasonably clean |
| Recent history | convert only the last months or years | old history is huge or messy, but recent context matters |
| Fresh start ("tip migration") | commit the current files as the first Git commit, and keep the old system read-only for reference | history is rarely consulted, or conversion is impractical |
A fresh start is often underrated: it's fast, gives a clean, small repository, and loses nothing, as long as the old server stays available read-only. Full conversions of large, old repositories can take days and bring along decades of large binaries.
Preparing the conversion
Whatever the source system, prepare these before converting:
-
An authors file. Old systems record usernames like
jsmith, and Git needsName <email>. Make a mapping file, in the format most tools accept:textjsmith = Jordan Smith <jordan.smith@example.com> alee = Alex Lee <alex.lee@example.com> buildbot = Build Bot <build@example.com> -
The branch and tag layout. SVN uses folders such as
trunk/,branches/andtags/, which become Git branches and tags. Non-standard layouts need explicit mapping. -
Large binaries. Plan to move them to Git LFS during or after conversion (article 43), or drop them with filter-repo before publishing (article 47).
-
Ignore rules and line endings. Translate
svn:ignoreproperties or.hgignoreinto.gitignore(article 8), and add a.gitattributeswith line-ending rules (article 35). -
Externals and subprojects.
svn:externalsbecome submodules, subtrees or packages (articles 41 and 42).
How converters work: fast-import
Most conversion tools read the old system's history and write a fast-import stream, a text format describing commits, which git fast-import turns into objects and refs. Writing a tiny stream by hand shows what every converter produces:
git init -q trail-guide && cd trail-guide
cat > ../history.fi <<'EOF'
commit refs/heads/main
mark :1
committer Sam Lee <sam@example.com> 1262340000 +0000
data 14
Initial import
M 644 inline lake.txt
data 16
Lake loop: 5 km
commit refs/heads/main
mark :2
committer Ana Diaz <ana@example.com> 1262426400 +0000
data 18
Fix lake distance
from :1
M 644 inline lake.txt
data 18
Lake loop: 5.4 km
reset refs/tags/release-1.0
from :2
EOF
git fast-import --quiet < ../history.fi
git log --format='%h %ad %an: %s' --date=short main
git tag
git ls-tree -r main
7db016f 2010-01-02 Ana Diaz: Fix lake distance
9de689f 2010-01-01 Sam Lee: Initial import
release-1.0
100644 blob 2d45d0569a0749b23a54175f4699c8993ca54097 lake.txt
- Each
commitblock names the branch, amarkother blocks can refer to, the committer with a Unix timestamp, the message (data <bytes>), its parent (from :1), and file changes (M <mode> inline <path>followed by the content). reset refs/tags/...creates a lightweight tag. Converters usually make annotated tags, with atagblock.- The original dates and people are kept, which is why converted history looks native in
git log.
Converters differ in how they read the old system, and in how well they map its branches, merges and metadata.
Subversion
git svn ships with Git, where Perl support is built in, and converts a repository directly:
svn log --quiet https://svn.example.com/trail-guide | awk '/^r/ {print $3}' | sort -u # list usernames for the authors file
git svn clone https://svn.example.com/trail-guide --stdlayout --authors-file=authors.txt --prefix=svn/ trail-guide
--stdlayoutmapstrunk,branchesandtags. Use--trunk,--branchesand--tagsfor other layouts.- SVN branches and tags arrive as remote-tracking refs under
refs/remotes/svn/. SVN tags are really copies that can change, so convert them into Git tags afterwards, with a small loop overgit for-each-ref refs/remotes/svn/tags, and create local branches from the rest. git svncan also act as a bridge during a transition:git svn rebasefetches new SVN revisions, andgit svn dcommitsends your Git commits back to SVN as revisions.- It's slow on large repositories, because it replays every revision.
For large or complex repositories, svn-all-fast-export (also called svn2git, from the KDE project) reads the SVN repository files directly with a rules file describing how paths map to repositories and branches, and is much faster. It produces fast-import output with proper tags.
TFVC (Team Foundation Version Control)
- Azure Repos has a built-in Import repository option that converts TFVC to Git, bringing only a limited recent window of history (180 days at the time of writing). Microsoft recommends this, or a tip migration, for most teams.
- git-tfs is an open source tool for full-history conversions, including branches:
git tfs clone https://dev.azure.com/acme/ $/TrailGuide/Main. - TFVC workspaces with many projects in one tree often become several Git repositories, and TFVC's per-file locking has no direct Git equivalent, though Git LFS locking covers binaries (article 43).
Mercurial
Mercurial is closest to Git in design, so conversion keeps history very faithfully:
git init trail-guide && cd trail-guide
hg-fast-export.sh -r ../hg-trail-guide -A ../authors.txt -M main
git checkout main
- hg-fast-export maps Mercurial named branches to Git branches, and bookmarks to branches, and converts tags.
- git-cinnabar lets Git work directly with a Mercurial server (
git clone hg::https://hg.example.com/trail-guide), useful while both systems are in use. - Mercurial's
defaultbranch becomesmasterunless you pass-M <name>, as above. Rename it later withgit branch -mif needed.
Perforce
git p4, included with Git where Python support is built in, imports Perforce depot paths: git p4 clone //depot/trail-guide@all. For large depots, Perforce's own tools and commercial services are common choices.
Verifying the conversion
Before switching, check the new repository carefully:
- Compare the latest files: export the old system's head revision, and run
diff -ragainst a checkout ofmain, ignoring the.gitfolder. - Count commits and branches:
git rev-list --count mainagainst the old system's revision count for that branch, andgit branch -aandgit tagagainst its branches and tags. - Check authors:
git shortlog -sne --allshould show only real names and emails, with no unmapped usernames. - Check size:
git count-objects -vHaftergit gc. A surprisingly large repository usually means binaries to move to LFS before publishing. - Push everything to the new host:
git push origin --allandgit push origin --tags.
Switching the team
-
Set a cut-over date. Freeze commits to the old system, run the final conversion or incremental sync, then make the old system read-only.
-
Explain the differences that trip people up:
Old habit In Git revision numbers ( r1234)commit IDs, and tags for releases commit sends changes to the server commit is local, pushshares (article 20)branches are expensive folders branches are cheap, and short-lived feature branches are normal (article 22) lock files before editing merge text files, lock binaries with LFS check out one folder of a big repository sparse checkout or separate repositories (article 44) -
Keep a mapping from old revision numbers to new commit IDs, for links in tickets and documentation. Many converters can write one, and
git svnrecords the SVN revision in each commit message by default (git-svn-id:).
What's current
- Hosting services increasingly expect you to convert locally and push. GitHub's importer, for example, stopped supporting Subversion, Mercurial and TFVC in 2024. Azure Repos still imports TFVC with limited history.
git svnandgit p4are included in Git, but need Perl and Python support respectively, which some minimal builds leave out.- Large migrations increasingly choose a recent-history or tip migration, with the old system kept read-only.
Common questions
Do I have to migrate all history? No. A fresh start, or only recent history, is often the better choice, as long as the old system stays readable for the rare cases when someone needs old history.
Why do converted commits show authors like jsmith <jsmith@a1b2c3-uuid>?
The conversion ran without an authors file, so usernames were turned into placeholder emails. Convert again with an authors file, or fix it afterwards with filter-repo's --mailmap (article 47) before anyone starts working on it.
Can people keep using SVN while we test Git?
Yes. Use git svn (or git-tfs, or git-cinnabar for Mercurial) as a bridge, fetching new revisions regularly, until the cut-over date. After it, make the old system read-only, so that nothing is committed to the wrong place.
Should the old repository become many Git repositories?
Often yes. SVN and TFVC repositories frequently hold many unrelated projects in one tree. Splitting them by project during conversion, with svn-all-fast-export rules or with filter-repo --subdirectory-filter afterwards, gives smaller, faster repositories.
Summary
- Choose full history, recent history or a fresh start. Keep the old system read-only either way.
- Prepare an authors file, a branch and tag mapping, LFS rules for binaries,
.gitignoreand.gitattributes. - Converters write fast-import streams.
git svnor svn-all-fast-export handle Subversion, git-tfs or Azure Repos import handle TFVC, hg-fast-export handles Mercurial, andgit p4handles Perforce. - Verify files, commit counts, branches, tags, authors and size before switching.
- Plan the cut-over, explain the workflow differences, and keep a revision-to-commit mapping.
Practice questions
Your SVN repository has 15 years of history, 40 GB of mostly binary assets, and nobody has used old history in years. What migration approach do you suggest?
Answer
A tip migration, or recent history only: commit the current files, with large binaries in Git LFS, as the start of the Git repository, and keep the SVN server read-only for reference. Converting everything would take a long time and produce a huge repository full of binaries that nobody needs in every clone.
After git svn clone --stdlayout, the SVN tags appear as remotes/svn/tags/1.0 instead of in git tag. Why, and what do you do?
Answer
In SVN, tags are folders created by copying, so git svn imports them as remote-tracking refs, like branches. Create real Git tags from them, for example git tag -a 1.0 -m "Release 1.0" refs/remotes/svn/tags/1.0 for each one, in a loop over git for-each-ref refs/remotes/svn/tags, then delete the remote-tracking refs before pushing.
List three checks to run before announcing that the Git repository replaces the old one.
Answer
Any three of these:
- Compare the latest files with the old head revision using
diff -r. - Compare commit counts per branch, and the lists of branches and tags.
- Check authors with
git shortlog -sne --all, looking for unmapped usernames. - Check the size with
git count-objects -vH, looking for binaries that belong in LFS. - Confirm everything was pushed with
--alland--tags.
Previous: How Git Stores Data: Packfiles, Garbage Collection, SHA-256, Reftable and Git 3.0
Next: Git Best Practices: Commits, Branches, Reviews and Repository Hygiene

More in Git Course
Quiz: Git Delicate Details
Twenty-five questions on Git's subtle corners: what commit -a and stash leave out, empty folders, ignore patterns and negation, HEAD~ versus HEAD^, ours and theirs in a rebase, tags that don't move or don't push, describe, merge reverts, diff exit codes, stash conflicts and more.
Quiz: Git Interview Questions
Thirty Git questions of the kind asked in developer interviews: Git versus GitHub, the staging area, merge versus rebase, fetch versus pull, reset, revert and restore, detached HEAD, conflicts, force pushing, stash, cherry-pick, reflog, bisect, submodules, LFS and how commits are identified.
Quiz: Git Course Final Exam (All Parts)
The final exam for the Git course: thirty questions across all twelve parts, from the three areas and staging through branching, remotes, undoing, history investigation, configuration, tags, larger projects, patches, rewriting, internals and troubleshooting.
Quiz: Professional Git Practice (Git Part 12)
Sixteen questions on migrating to Git from Subversion, TFVC and Mercurial, team best practices for commits, branches and reviews, repository hygiene, and diagnosing and fixing the most common Git errors, with explanations.
Discussion
Sign in to ask a question or share what you learned.