Git-TF Getting Started With Git To TFS Integration

22. August 2012 11:09 by Administrator in Source Control, TFS  //  Tags:   //   Comments (1)

Having been using TFS for source control for a while I have learnt that some things in TFS should really be avoided like branching and merging, I think most people that have attempted this have been burnt in the past!  Other things that I find irritating in TFS:

  1. The concept of workspaces and having readonly files everywhere that need checking out before you can edit them
  2. Default merge does't do a three way merge (you can change this though) 
There is a great post from Martin Fowler that shows where TFS sits compared to the other major players such as SVN, Git and Mercurial: and also a survey of ThoughtWorks developers which is interesting.
The tech stack that I'm using for this article is:
- Windows 7 (64bit Enterprise)
- TFS 2010


Microsoft have just released Git-TF which is a set of cross platform tools that allow you to exchange changes between TFS and Git.  It makes it really easy to clone code from TFS (including changeset comments), pull updates and checkin changes from local Git back to TFS.
Using git locally essentially gives you unrestricted branching and merging, a local playpen, flexible workflows, best practices, and source control that goes way beyond just checkin/checkout.
As I'm discovering Git has a bit of a learning curve but once you start using it the limitations of TFS and other SCM tools soon become clear. For example branching in the same working folder which means no more creating whole new folder structures, fantastic!

Getting Started With Local Git and TFS (Windows 7)

To get up and running is quite quick and simple:

  1. If you haven't already done so install Java from
  2. Download and install Git:
  3. Download and extract Git-TF to a local directory such as c:\git-tf:
  4. Add c:\git-tf (or where ever you extracted Git-TF to your PATH environment variable)
  5. Read the Git-TF html guide as this provides some useful info about working in teams

Additional Useful Git Tools and Extensions

If you are used to SVN or TFS shell extensions then you should install TortoiseGit from here:
I found that I had to reboot after installing TortoiseGit to make the nice windows explorer icons appear.

Git To TFS Workflow

From my initial experiments I have found the following basic (I'm still learning!) workflow useful from the command line or PowerShell:
NOTE:  The master branch always matches the TFS codebase:
  1. git tf clone http://tfsServerName:8080/tfs $/TeamProject/AppName
    This will create a new local Git repo with the latest changes from TFS
  2. git status 
    I have noticed that sometimes when clonning from TFS for some reason Git thinks that I have modified another developers changeset so if after running git status it shows you a load of modified files then run:

    git checkout -- .

    This will undo ALL modified files on the current master branch 
  3. git checkout -b develop

    This will create a new branch called "develop" and switch over to it (notice how quick and easy it is!!)
  4. Modify some files on the develop branch
  5. To check what I have changed:
    git status 

    This will display a list of modified files 
  6. Commit files to the develop branch
    git commit -a -m "my comment"
  7. Merge develop back into master and then checkin to TFS
    git checkout master 
    git-tf pull --rebase
     (always get the latest from TFS before merging)
    git merge develop
    git-tf checkin 

This may seem like a few extra steps but once the repo has been created and you start to see the benefits of using Git locally it's all worth it.

Additional Resources and Further Reading

Common Problems and Workarounds

After experimenting I came across the following problems: 

git-tf: Cannot cherry-pick commit '{ID}' because it has 2 parents, only commits with exactly one parent are supported.

This seems to happen if your're trying to checkin to TFS but haven't followed the checkin workflow in step 7 above.  This message appears  when doing a git-tf pull --rebase. To work around this do:

git-tf fetch
git merge FETCH_HEAD



Comments (1) -

8/22/2012 9:37:20 PM #

Please clarify if this is relevant to VS 2012 / TFS 2012 or if this article is referring to older tech - VS 2010 / TFS 2010 (SP?).

Pingbacks and trackbacks (1)+

Add comment

  Country flag

  • Comment
  • Preview