Combining TFS Version Control and Git with Git-TF

 

For a customer I am (together with my colleague Jasper Gilhuis) setting up a hybrid solution regarding Version Control. Some Scrum teams use Git as their primary Source Control system and most of them use TFS Version Control.

What we see at different organizations is that it requires the teams to check-in all code on a TFS branch. Most of the times this is needed to facilitate the release process or to facilitate auditors. However, some teams do not like to work with TFS Version Control or cannot work with TFS Version Control (e.g. XCode developers. What happens is that teams maintain duplicate repositories. The “Git” teams set up a TFS workspace and a Git Repository. All the work is done in the Git repository and when the work is done, the files are copied to the TFS workspace.

This works quite well, but traceability is hard. Git teams do not have work item integration and therefore do not associate work items with their commits. Only when the code is checked in to TFS, work items can be related. Because this is done afterwards (the work is done within Git) this is hard and manual labor.

image

Using TFS 2013 and Git-TF

If you are new to Git terminology, read my blog about some definitions.

With the introduction of TFS 2013 new opportunities arised. TFS 2013 is now a full-blown Git Provider and offers new possibilities for Git teams.

  • Git Teams can synchronize with TFS. This means their code is stored within the organization database and backed up etc.
  • With Git-TF, Git Teams can automatically sync between Git repositories and TFS without needing a TFS Workspace

MSDN has some good articles about setting up Git repositories so I will not repeat how to do this here.

Once you created a Git Repository in TFS, you can commit and push changes to it. The great thing about using TFS as your Git provider is that you can use the Work Item Link feature. In TFS Version Control you use the Team Explorer to relate your work item to your check-in (I talk a little about it here). In Git it is actually  much simpler. Just provide a #workitemid in the commit message and TFS does the rest once you push it to the repository.

image

Because the linking is done on the TFS server once it is pushed, this works with any Git client you use. from the command line, SourceTree (which is great !), XCode etc. it all just works.

Synchronizing repositories

Now that you have a Git Repository you can hook it up with a TFS Version Control repository, branch or folder. What you need to do for that is the following:

  • Download Git-TF and make sure you get version 2.0.3.20131219
  • Follow the Getting Started Guide and install Git-TF. (Java Runtime is needed for this)
  • Add Git-TF to you path in the Environment variables
  • Open a command prompt and navigate to your Git Repository Directory. This is the location where you cloned the Git Repository
  • Type
    git-tf configure http://tfsserver:8080/tfs/CollectionName $/TeamProjectName/[Branch]/[Folder]
  • The repository is now connected to TFS
  • Use git-tf pull to get changes from TFS Version Control in your repository
  • Use git-tf checkin to checkin  changes to TFS Version Control

When you use git-tf checkin, it merges all Git commits to 1 changeset in TFS. You can use

git-tf checkin –-deep

to checkin all commits as separate changesets.

image

 

Getting traceablilty

When you commited messages in Git with #workitemid and you executed git-tf checkin, the relation with the work item is lost. The relation is visible in the Git repository, but not in the TFS Version Control.

The great news is that in version 2.0.3.20131219 they added an extra option to the git-tf checkin. –mentions

When you use this, all associated work items in the Git commits are also associated to the equivalent changesets.

git-tf checkin –-deep –-mentions

So after you run this command you get full traceability!

image

Summary

Using TFS 2013 allows you to really integrate cross-platform teams and give them freedom of choice when it comes to tooling. If you set up git-tf and use the –-deep and –-mentions options you get synchronization and traceability for free!

Links and Resources

A lot has been written already on Git and TFS. Hereby a few links

Fellow MVP Gian Maria Ricci has written a lot on Git and TFS. You can find his blog here

Other resources mentioned in this post

Advertisements

2 Responses to “Combining TFS Version Control and Git with Git-TF”

  1. Reblogged this on Jasper Gilhuis and commented:
    Great post on utilizing the power of Git in combination with Team Foundation Version Control

  2. My best advice is, for a lot of reasons, to better use [git-tfs](https://github.com/git-tfs/git-tfs) instead of git-tf….

    The more I ear of users satisfied by git-tf, the more I think that Tfs user ignore the word ‘branch’ and never use it…. Git-tfs manage branches! And much more…

%d bloggers like this: