How to migrate from TFS to Git

Thu, Oct 11, 2012

Team Foundation Server or TFS as it is popularly known, is Microsoft’s answer to revision control software especially the popular Linux-derived versions of such software such as Git. As with over versions of software from Redmond, there are a variety of complaints popularly associated with TFS which lead to software developers and teams wanting to migrate from this revision control software option to other options that offer them better advantages depending on their particular situation. Some developers simply want to be able to work with both TFS and other revision control software tools like Git.

Git, is a distributed revision control and source code management system initially developed by Linux founder Linus Torvalds for the Linux operating system. When people who have tried to work with TFS decide they can no longer do so or want to combine options, Git is usually one of the first options they consider. Several advantages are associated with this software, the first of these advantages being that it is free, can be installed on an internal server like GitStack or used with public or collective repositories that depend on it for their infrastructure such as GitHub.

The Git option is so popular that Microsoft in 2012 announced TFS integration with Git in order to curtail the migration yearnings of people bored with the TFS option. The integration solution known as Git-tf, allows users to work with Git repo – branch, commit, edit, commit, branch, merge as well as other options and then move the content to be shared or stored on a TFS repository. The logic of Git-tf is one-sided and aims to move Git aficionados over to Microsoft’s TFS, although Microsoft actually does claim it is in order to support teams that are known to work with both solutions.


Git-Tf – Supports Git to TFS Migration or Integration


For those who beg to differ and insist on TFS to Git migration, perhaps not as a means of abandoning the Microsoft solution but also to share their work with people who work with Git as a central revision control system instead, Git has several options typically called Git/TFS bridges, which are primarily developed by members of the open source community versus typical Redmond solutions developed by individuals paid to do so.

The most popular TFS to Git migration option is a plug-in similarly named to the Microsoft solution called Git-tfs. It came on scene in 2009 and has undergone several revisions in alignment with the changes that frequently occur with the TFS software and also to ensure consistent cross-compatibility. Git-tfs is a two-way solution; it helps people move from TFS to Git and vice-versa.


1. Installation

The most important thing you need to begin is to have your own version of Git installed or if you have it on a central repository, that’s equally fine as well. After this you’ll have to download Git-tfs, you have a variety of locations to choose from. The most reliable download location is the plug-in repository on GitHub where you can download the zip files from and install the software on your Windows system. If you download the Git-tfs source code instead of the executable, you will need to compile it using the Visual Studio SDK, which you should already have on your system. There is an exe version as well but note that it will not run if the .NET framework is not installed on your system, the same applies for the source code.


2. Clone Your TFS version

Once Git-tfs is successfully installed you can copy your source code from TFS by taking advantage of the “git tfs clone” command option as shown below:
git tfs clone http://tfs:8080 $/TeamProject/git_folder
If you’re using the TFS version 2010 or later, you might want to use the following command:
git tfs clone http://tfs:8080/tfs/DefaultCollection $/TeamProject/git_folder
For those who don’t use default credentials, you will need to use the – –username option:
git tfs clone — –username tfs\tfssetup http://tfs:8080/tfs/DefaultCollection $/TeamProject/git_folder

A dialog box should show up so you enter your password when the command is about to execute. Make sure that the folder you are copying the Git source code to is different from where you do your TFS work. The end-result should be two versions of source code one which is TFS and the other Git.


3. Solution File Problems

Of course there’s the annoying issue of solution files that connect to TFS once the solution is opened. The easy way of handling this problem is to disconnect from the Internet once the solution is opened forcing it to open in offline mode via the browser. The solution will then open normally, after this you can reconnect to the Internet. Alternatively you can always opt for the tedious option of removing the source code links. The final option is to install the GoOffline solution from Microsoft. It’s a free Visual Studio add-in which places a Go Offline button in the Source Control menu. Once the solution is in offline mode, any file renaming or moving happens without a need to communicate with the TFS server.

GoOffline Add-In


4. Shelving Changes

Once your changes have been made and your latest update to your code on the Git repository is committed to memory, you can update the TFS version of the code by using the shelveset technique. The way this works is that all local changes you make are aggregated into a shelveset and placed on the server. This way you don’t need to worry about rewriting local history or having multiple shelvesets on the server that you would have to process in chronological order.


Changes can now be made using the “git tfs shelve” command like this:
git nfs shelve “shelveset name”

Once this is done, move over to the TFS version and go to the “Pending Changes” window where you can unshelve the new shelveset. If everything is perfect revert to the regular TFS check in with the associated policies used.


5. TFS to Git Update

The above listed shelving changes apply when you are updating from Git to TFS. When you want to work on TFS and update your Git repository, the command required is “git tfs fetch” which collects the latest changes in tagged objects format from the relevant server although they changesets won’t be applied automatically. To apply them you need to use the ”git merge” command which applies the tagged object changesets to your Git repository.

git tfs fetch -i $/TeamProject/Branch/Component
git merge tfs/$/TeamProject/Branch/Component

Conclusion

Git-tfs is an effective tool for not only migrating from TFS to Git but interfacing between both revision control systems effectively. The plug-in versions available from the developer Matt Burke, change frequently to cope with TFS changes, so make sure that before use, the version of Git-tfs you have is up to date. However, should any concerns or problems arise, multiple sources of information are available on the Internet which cater to users of this resource. The GitStack’s team can also provide you an additional technical support during your migration process.