Migrating from TFS to your favorite Git Provider, preserving History

Hélio Rocha
2 min readMay 14, 2020

Git is, or is becoming, the de facto standard for code versioning. Following this, it’s only natural that people start migrating from their current platforms into others like GitHub, GitLab or BitBucket. I hope this post helps you perform that endeavor while keeping your valuable historical data. This example is based on a migration from TFS to GitHub but it can be replicated for whatever Git provider you choose.

The migration will consist of three simple steps: Clone, Clean and Push.

I’ve created a small test TFS repo on Azure DevOps, added a file and updated that file, as you can see below.

The Clone

For each task there’s the perfect tool and the perfect tool for pulling code from a TFS repository is “git-tf”, available on chocolatey and homebrew package managers.

After installing it, just clone your code using the following command (you’ll probably be asked for a password, so don’t forget to create a Personal Access Token in your Azure User Settings).

#git tf clone <TFS_COLLECTION_URL> <TFS_PROJECT_PATH> <GIT_REPO_NAME> --deep

The Clean

With the code cloned, it’s now time to clean up TFS references and get it ready for a Git repository.

Start by adding/modifying a .gitignore file to the root of your repository. In doubt, download from GitHub the one that makes more sense to you.

Don’t forget to commit it:

git add .gitignore
git commit -am "adding gitignore"

Then, edit .git/config file and remove the references to TFS, it should look like this

[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
precomposeunicode = true
autocrlf = false

The Push

We are now in the finish line. Just create a new repo in your favorite git provider, add the new remote and push your code to it’s new home.

git remote add origin git@github.com:hjrocha/test-tfs.git
git push --set-upstream origin master

And, as you can see, a new repo is born with the existing content and all historical data.

Let me know your thoughts about this process.

--

--