Use Git superpowers in a shadow of TFS

So you have a project in TFS? And you are not satisfied with code comparison and history of your work? Believe me, you are not alone, in this topic. Many projects have been developed with this technology since 2005 (when TFS was released), but if you are not satisfied you can switch to the Git. Probably in a perfect world, that would be pretty easy… yeah but what about the whole infrastructure build upon TFS? Builds, CI, CD etc. So today I would like to show you a solution to use a Git in a background and don’t break existing resources.

How map a TFS repo to GIT?

Let’s start with installing a great tool to map our TFS source control to Git:
Install git tfs:

Then you need to clone a repository, you can use a clone command or a quick-clone, in the second option you wouldn’t download the whole history.

git tfs quick-clone http://tfs-repository-link $/RepositoryName –debug –ignore-regex=’DirectoryToPass/’ –resumable

Why I’ve used –debug flag? If you omit it you wouldn’t know what is happening, if your repo is big, you may think that process is frozen. Resumable is pretty useful when an error appears during download.

Ignore-regex gives us a possibility to pass some directories or files.

What to do when you can’t unshelve the shelvset?

If you’ve used quick-clone before, to unshelve something you need a changeset history of the shelveset. During unshelving, probably you will get an error like this:

ERROR: Parent changeset CXXXX not found.

Where XXXX is the changeset ID.

In that case, you should run the following method to find the changeset:
git tfs fetch -c=XXXX -d –ignore-regex=’DirectoryToPass/’

It should download all the history of the changeset and its parent. Use -d or –debug to see what’s going on during the downloading. It can take a while…

Creating a new code

  1. Go to the directory where you have your Git repository
  2. Run in the terminal, and get the newest changes:

git tfs fetch

  1. Create the new feature branch:

git  checkout -b BRANCH_NAME

  1. Open the solution in the Visual Studio, implement code and make some commits. Push commits to the server, share a code, and feel the power of Git!
  2. At the end of your work, create a shelvset – make sure that you are currently on a branch where you’ve made all changes. Git will put on shelve all commits that are different to master in this branch. Use git branch command.
    To create a shelvset run:
    git tfs shelve  SHELVSET_NAME
  3. Your shelvset should appear on TFS, then you can run builds.

Creating a new shelvset from exact commits

  1. Move exact numbr of commits to the new branch, e.g.:
    1. git branch BRANCH_NAME HEAD~3
    2. in this case we are moving 3 last to the new branch called BRANCH_NAME
    3. You can use also use: git branch BRANCH_NAME <sha1-of-commit> – it requires sha1 of a commit
  1. Move a specific commit to the branch :
    1. make sure you are on the branch you want to apply the commit to (e.g. git checkout master)
    2. Then run git cherry-pick <sha1-of-commit>, it will copy a commit without previous history to the branch (probably you will have some conflicts…)

Unshelve a code to use it in Git

  1. Go to the directory where you have your Git repository
  2. Run in the terminal:


Notice that changes will be put in a new branch, so probably you would need to use git checkout.
If an error appear to see: What to do when you can’t unshelve the shelvset?

Use it today

Like you can see, mapping TFS repo to Git is pretty simple if you wouldn’t have unpredictable problems. Try to think how much time you can save on conflicts and code sharing, happy coding!


Please enter your comment!
Please enter your name here

Loading Facebook Comments ...