Migrating from TFS to Github

Posted by Jarren Long at 2016-06-15 16:49:52

After a good run of using visualstudio.com's free Team Foundation Server for storing one of my projects, I decided today that it was time to get all of my projects back in one place. As much as I like TFS, I decided that (since most of my active projects were already over there anyways), that I would go ahead and migrate my project back to my GitHub account. But what to do about my commit history? The last time I migrated a project between Version Control Systems, I lost my entire change history! Not good. A quick search on Google found me exactly what I needed, a nifty little tool called Git-TF, which boasts the ability to migrate repositories from TFS to GitHub without losing any of the repository's change log.

1. Installing Git-TF

Step 1 in getting the tool to work was to download and install it. This was pretty easy, the CodePlex page for Git-TF has a handy download link to the latest version (which is a zip file). After a quick download and extract, I tried to run the tool, to no avail. Turns out Java is required. Download & install the latest JRE, and retry...got a help message, it runs.

2. Cloning the TFS repository (with full history)

The next step was a bit trickier. The tool needs the latest copy of the TFS repository that is going to be migrated. However, to clone the repository, I needed to configure Alternate Credentials on my visualstudio.com account. It took awhile to find a recent enough article on how to do this. After some trial and error, it's easier than it should be:

  • Log into your visualstudio.com account
  • In the top-right corner, click on your name and select My Security TFS to Github
  • In the new window, click on "Alternate authentication credentials" on the left
  • Make sure the "Enable alternate authentication credentials" checkbox is checked
  • Enter a secondary username and password to use, and click save TFS to Github
  • Once this was done, it was just one command from a Command Prompt to clone my TFS repo:
git-tf.cmd clone https://jarrenlong.visualstudio.com/DefaultCollection $/Sphere --deep

Note: If you didn't follow the Git-TF instructions and add the Git-TF root directory to your system path, just use the full path to the fit-tf.cmd file when executing the command. Since I only planned on using this tool once, this is what I did.

This did take awhile to clone, as it is pulling the entire TFS repo history with it. Just let it cook until it's done. Note that this is the only time that you actually need to use the Git-TF tool. The last few command just use your regular git client.

3. Prepping the TFS repository for migration

Before you finish the migration, you need to clean up a few things:

  • Delete any .vssscc files in your repo, these are TFS source control bindings (you won't need them anymore)
  • Use a text editor to modify all of your .sln files, and delete the "GlobalSection(TeamFoundationVersionControl) ... EndGlobalSection" blocks
  • Optional: Add .gitignore and .gitattributes files to the root directory of your repository to tell Git what to ignore, and how to handle files in your Git repository

4. Create your new GitHub repository

You will need a new GitHub repository to migrate your TFS code into. Log into your GitHub.com account and create a new repository. If you're reading this article, you probably know how to do this.

5. Commit the TFS repository to GitHub

The last step in the TFS to Git migration is to add all of your project files to your new Git repository, commit them, then bind them to your new Git repository, and then push the changes. Execute these commands from the root of your repository.

git add .
git commit -a -m "Migrated from TFS repo"
git remote add origin https://github.com/JarrenLong/Sphere.git
git push origin master

Once this finishes (again, may take awhile), log into your github.com account and view the repository. Your project and all of its files should now be there, along with their complete history from TFS!

TFS to Github