Using Git to manage TFS source control

As everyone knows, the TFS 2010 Version Control System (VCS) is Centralized. That’s a good thing, but if you ever used a Distributed Version Control System (like Git) you might encounter some shortcomings and feel a little bit frustrated about some annoying things.

The biggest advantages to use DVCS (for me) are the advanced merging possibilities and the offline repo access. When I’m working at home, I can see the full history of the project, every single checkin, without starting up my VPN connection to work and can work like I were at work: checkin, checkout, branch, merge,.. 

Note that with TFS11, there will be local workspaces (as described in Brian Harry’s blogpost). In local workspaces, TFS assumes that your client is master and TFS needs to understand the changes that you make there.

So.. will TFS11 be a DVCS then? No, as Brian Keller mentioned:

I’m certain that about this time, I bunch of people are asking “but, did you implement DVCS”.  The answer is no, not yet.  You still can’t checkin while you are offline.  And you can’t do history or branch merges, etc.  Certain operations do still require you to be online.  You won’t get big long hangs – but rather nice error messages that tell you you need to be online.  DVCS is definitely in our future and this is a step in that direction but there’s another step yet to take.

Ok, back to the essentials of this post: What if you want to use the power a DVCS system like Git and combine it with source control on TFS? You can, using GIT-TFS. This is a Git extension acting as a two-way bridge between TFS and Git. It lets you treat TFS source control as a remote repo. Basically all it does is provide you some Git commands that let Git work against your TFS source control. I’ll show you some possibilities:


Getting started

First of all, you need a version of Git on your machine. I use Git For Windows and this works very well (it also gives you a GUI to visualize changes and merges). The next step is to download Git-TFS (a .zip file). After the download, unzip it to specific location (for example C:/GitTfs/) and add this location as an evironment path of your machine. That way you can use the Git-TFS commands in the commandline.

System Properties -> Advanced -> Environment Variables and edit the path variable. Add the Git-TFS path to the Variable value


To check if your Git-TFS will work, just open a commandline window, and enter ‘git tfs’. You should see a list of the available commands. Type ‘git-tfs help [command]’ to get some information about a specific command.


Get your source from a TFS repository

Getting your repo sources from TFS is extremely easy using:

git tfs clone http://tfs_server:8080/Collection $/your_project destination

In my example, I cloned a test project


Note that you get all revisions, which are all stored in your local Git repo.


Make some changes and check-in on TFS

The next thing we can do is change some code. After the change has been saved, we have to commit to our Git repository using:

git commit -am “My checkin”

(Be sure to do this on the correct folder level, otherwise Git will not find your .git repo). This is a general commit command for Git. For more information about Git command, check this link

Now that the changes are commited to Git, they need to be pushed to our TFS Source Control. Do this with:

git tfs ct

You will see the check in dialog so you can check-in your changes because you supplied the “ct command” (checkintool).


Once the check-in is completed, git-tfs automatically pulls the changeset from the TFS server and merges the change locally in your repository. This is how it looks like:


You can see the changes in the source control history from TFS.



Get changes from TFS in our Git repository

The next thing we want to do is the opposite: Get some changes from TFS in our local Git repo. First change some source code directly from TFS, and do a check-in. All we have to do now is:

git tfs pull

This does an update of your local Git repository with the latest version from TFS.



Git-tfs is really easy to use, and if you’re an advanced Git user but forced to use TFS source control it’s the way to go! I’ll also give you some interesting links:

Git workflows with git-tfs:

Git-tfs recent improvements

Thanks for reading!

Written by
Alexander Vanwynsberghe
Join the discussion


Alexander Vanwynsberghe

Belgium-based entrepreneur. Into technology, innovation and a bit of cycling and running too. Evangelist for everything related to smart-tech.