How to Migrate from TFS to Git: A Step-by-Step Guide
In this article
To migrate from TFS (Team Foundation Server) to Git, you need to export your source code, history, and work items from TFS, then import them into a Git repository, typically using a tool like git-tfs or Azure DevOps' built-in import feature. The exact steps depend on your TFS version, the size of your codebase, and whether you also need to migrate work items, build definitions, and other team processes.
Background: Why Teams Leave TFS for Git
Team Foundation Server (now Azure DevOps Server) has been a staple for .NET teams since 2005, offering centralized version control, work item tracking, and build automation in one platform. However, Git has become the industry standard for version control due to its distributed nature, faster branching and merging, and strong support in modern tools like GitHub, GitLab, and VS Code. Many teams migrate to Git to align with open-source workflows, enable better collaboration across distributed teams, and simplify integration with CI/CD pipelines. The migration process is often more involved than just copying files—it requires preserving history, handling branches, and deciding what to do with TFS-specific artifacts like work items and build definitions.
Understanding TFS and Git: Key Differences
TFS uses a centralized model: there is a single server that stores all versions, and clients check out files and check in changes. Git is distributed: every developer has a full copy of the repository, and changes are shared via push/pull operations. This fundamental difference affects how you migrate:
- History: TFS tracks changesets (each check-in), while Git tracks commits. The migration tool must convert changesets into commits, preserving author, date, and message.
- Branches: TFS branches are often separate folders or server paths, while Git branches are lightweight pointers. The migration tool must map TFS branch structures to Git branches.
- Work items: TFS work items (bugs, tasks, etc.) are linked to changesets. Git commits can reference work items via commit messages, but the link is not automatic unless you use Azure DevOps integration.
- Builds and releases: TFS build definitions are server-side; Git uses pipeline definitions (YAML or classic) that are often stored in the repository. These need to be recreated or converted.
How to Migrate: Step-by-Step Process
The most common approach is to use git-tfs, an open-source tool that bridges TFS and Git. Here is a typical workflow:
- Prepare your TFS environment: Ensure you have access to the TFS server and the necessary permissions (read access to source code and work items). Install Git and
git-tfson a machine that can reach the TFS server. - Clone the TFS repository as a Git repo: Run
git tfs clonewith the TFS server URL and the path to the branch you want to migrate. This creates a local Git repository with the full history converted. - Clean up the history: After cloning, you may want to remove large files or sensitive data (like passwords) from history. Use
git filter-branchorgit filter-repoto rewrite history if needed. - Push to a Git hosting service: Create a new repository on GitHub, GitLab, Azure Repos, or Bitbucket, then add it as a remote and push your local repository.
- Migrate work items: If you need to preserve bugs, tasks, and other work items, use Azure DevOps' built-in migration tools or third-party tools like OpsHub. Alternatively, export work items to Excel and import them into the new project.
- Recreate build and release pipelines: Rewrite your TFS build definitions as Git-based pipelines. In Azure DevOps, you can create a new pipeline and point it to your Git repository.
- Update team processes: Adjust your branching strategy, code review policies, and other workflows to fit Git. Train your team on Git commands and best practices.
Choosing the Right Migration Tool
Your choice of tool depends on your specific needs:
- git-tfs: Free, open-source, and works well for code and history. It does not migrate work items or build definitions. Best for small to medium repositories.
- Azure DevOps Migration Tools: A set of open-source PowerShell scripts that can migrate work items, test plans, and other data between TFS/Azure DevOps projects. Good for teams that want a complete migration.
- OpsHub Migration Utility: Commercial tool that automates migration of code, work items, and other artifacts. Useful for large, complex migrations.
- Manual migration: For very small projects, you could export source code and re-commit it to Git, but you lose history.
Common Problems and How to Avoid Them
Migrating from TFS to Git often hits a few snags:
- Large history: TFS repositories with many changesets can take a long time to clone. Use
git tfs clonewith the--branchesoption to limit what you migrate, or split the history if needed. - Branch conversion: TFS branches may not map cleanly to Git branches. Check the resulting branches and rename or restructure them as needed.
- Author mapping: TFS usernames (e.g., DOMAIN\user) need to be converted to email addresses for Git. Use a
.mailmapfile or configure git-tfs to map users. - Binary files: Large binary files can bloat the Git repository. Consider using Git LFS for such files before migration.
- Work item links: After migration, links between commits and work items may be broken. In Azure DevOps, you can re-link them using the migration tools.
Costs and Time Considerations
The cost of migration depends on the size of your codebase and the tools you choose. git-tfs is free, but it requires manual effort and technical expertise. Commercial tools like OpsHub can cost money but save time and reduce risk. The time required varies: a small project with a few hundred changesets might be done in a day, while a large enterprise repository with years of history could take weeks. Also, consider the ongoing cost of hosting Git repositories—many services offer free tiers for small teams, but larger organizations may need to pay for advanced features like code review, CI/CD, and security.
Safety and Verification
Before you begin, ensure you have a full backup of your TFS server and that you are not deleting anything until the migration is verified. After migration, verify that:
- The Git repository contains all branches and tags.
- History is intact—check a few random changesets to confirm commits, authors, and dates.
- Work items are present and linked to commits (if you migrated them).
- Builds and releases work with the new Git repository.
- Your team can clone, commit, and push without issues.
Frequently Asked Questions
Can I migrate from TFS to Git without losing history?
Yes, using git-tfs or similar tools, you can convert the full TFS changeset history into Git commits. The process preserves author, date, and commit messages, though you may need to map usernames to email addresses.
What happens to my TFS work items after migration?
Work items are not migrated by git-tfs. You need a separate tool like Azure DevOps Migration Tools or OpsHub to move work items. Alternatively, you can export them to Excel and re-import them, but links to commits may be lost.
Can I migrate only a specific branch from TFS to Git?
Yes, with git tfs clone you can specify a particular TFS branch path. This is useful if you only need the main branch or a specific release branch.
Is it possible to migrate from TFS to GitHub?
Yes, after creating a local Git repository with git-tfs, you can push it to GitHub just like any other Git repository. The same applies to GitLab, Bitbucket, or Azure Repos.
What is the best way to handle large files in TFS during migration?
Identify large files (e.g., binaries, videos) and move them to Git LFS before or after migration. You can use git lfs migrate to convert existing history to LFS pointers, which keeps the repository size manageable.
Do I need to shut down TFS during migration?
No, you can perform the migration while TFS is running, but you should avoid making changes to the source code during the clone process to ensure a consistent snapshot. After migration, you can decommission TFS once the new Git repository is verified.