Migrate From TFVC to Git

melih orhan
inventiv
3 min readMar 29, 2019

--

In Inventiv, we have used a Team Foundation Server(TFS) to store our source codes. Likewise, we have used Team Foundation Version Control (TFVC) as source control. For a long time, we haven’t seen the need to migrate them to Git. But as the projects grew, it became difficult to manage them. When we are in TFVC, it is quite troublesome to open the branch for each feature/issue. I remember the time when we have been dealing with merge conflicts for hours before the deployment.

When we have heard of feature branches, of the Git Flow branch model and we have decided to use it. So, we have started to move everything to Github from TFS.

You’re currently on TFS and would like to migrate to Git? You can migrate them to Git repos using the git-tfs tool without losing your history. This post shows you how.

Git-TFS

Git-tfs is an open source tool hosted on Github. It is a two-way bridge between TFS and git. It also allows you to do your local development in a Git repository, and still synchronize your work with a TFS server.

Installation

  • Open your favorite command tool(power shell or windows CLI) the prompt as administrator mode. I usually prefer the powershell.
  • Install the Chocolatey package manager (It is a package manager similar to npm). You can follow this link for installation.
  • Check for chocolatey installed or not, by executing choco — version command

choco — version

  • Then install git-tfs. Execute the following command.

choco install gittfs

Check for git-tfs is installed or not, by executing git-tfs — version command. If it returns null, add git-tfs.exe path to the environment variable.

git-tfs — version

Setup for the migration

If git-tfs is successfully installed, you can clone your source code from TFS.

Command options as shown below:

List of remote branches on TFS

The list-remote-branches command helps you find the branches to clone of a TFS server. So, you can find a TFS repository path to clone.

git tfs list-remote-branches http://tfs:8080/tfs/DefaultCollection

Cloning

The clone the command fetches all the changesets from TFS. If it does not exists, it will be created a new git repository. If you have a large TFS repository, a full clone will take a long time to create.

git tfs clone http://tfs:8080/tfs/DefaultCollection $/Project/Path

If you are impatient, you can use the quick-clone command. So, you create a git repository with a snapshot of the latest version from TFS.

git tfs quick-clone http://tfs:8080/tfs/DefaultCollection $/Project/Path

or you can create a git repository with a specific changeset from TFS, as shown below.

git tfs quick-clone http://tfs:8080/tfs/DefaultCollection $/Project/Path -c=1457

If you are successfully cloned from TFS, you can run git log command to see the imported commits.

git log

You can push your source code to the remote repository. You can follow this link for it.

Congratulations! I hope you have succeeded :)

Fetching new changesets from TFS

Other developers may still be working on TFS. You’ll want to move the changes to git. It is quite easy.

The git tfs pull command fetches TFS changest and merges the current branch with the commits fetched.

git tfs pull

You can push is used to uploading local repository commits content to a remote repository

git push

Conclusions

That is it, with these commands, migrating is pretty easy.

However, from an organizational point of view, there are a couple of more steps required. You have to teach your team how Git actually works.

If you have any specific questions, please let me know in the comments.

Take care :)

Source Links

https://github.com/git-tfs/git-tfs

https://git-scm.com/book/en/v2/Git-and-Other-Systems-Migrating-to-Git#_git_tfs

--

--