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.
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.
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:
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.
Before you finish the migration, you need to clean up a few things:
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.
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!