TFS to Git Migration

tfs-to-git

Version control system is a system which tracks and provides control over changes to the source code. There are two types of version control system:

  • Centralized version control system
  • Distributed version control system

Centralized version control system

In this control system, each developer is connected to the server. Changes are directly pushed to the server and other developers need to update local repository directly from server. Best example of centralized version control system is TFS i.e. Team foundation server

Image result for distributed version control system

 

Distributed version control system

In distributed version control system, each developer has his/ her own personal source control repository. When a single developer commits his/her changes then it present on their own repository. For every commit it generates new version of source code and avoids data loss. After task is ready to consume by other developers, developer needs to push his/her changes to the server. This steps is like pushing code to the server in centralized version control system. Best example of distributed version control system is Git.

Image result for distributed version control system

 

Now I am introducing way to move your source code from TFS to Git without losing you change set history.

Step 1: Open power shell or command prompt in elevated mode.

Step 2: Install chocolatey package manager

Step 3: Cross check for chocolatey installed or not, by executing choco -? command.

Step 4: Install git-tfs. Execute following command

C:\> choco install gittfs

git-tfs is a two-way bridge between a TFS and local git repository.

Step 5: Cross check for git-tfs is installed or not, by executing git-tfs -? command. If it returns null, add git-tfs.exe path to the environment variable.

Step 6: Export your source code from TFS to the local folder using following command. It extracts your source code with change set history.

Syntax:

git-tfs<space>clone<space>your tfs location<space>project location path<space>Local repository path

examaple:

git-tfs clone http://tfs.prasadt.com:8080/tfs/projects $/Main/Source/HelloWorld D:\Migration\HelloWorld

1

Step 7: Execute git gc. gc stands for Garbage collect.

2

Step 8: Execute git-tfs cleanup. It cleanup work space directory.

2

Before next step if you are working in organizational account, then some settings in .gitConfig and .git-Certs file.

Step 9: Push your source code to Git

Syntax:

git remote add origin “Your git repository path”

git push origin master

Example:

git remote add origin http://tfs.prasadt.com:8080/tfs/beconnect/_git/HelloWorld

git push origin master

Now your code successfully migrated from TFS to Git without losing your change set history.

Happy coding.

Image source: @Google image and snap shots from my computer.

 

 

 

 

 

7 thoughts on “TFS to Git Migration

  1. Pingback: Migrating from TFS to Git - QuestionFocus

  2. What happens when you add projects in Visual Studio and check them in via TFS? How does the cloned Git repository keep up with those changes? Do you have to do another Clone? Also…should you then reconfigure Visual Studio to commit changes to the new Git Repository? Or do you just have to periodically push the cloned Git repository?

    Like

    • It is a broad question, still will answer
      What happens when you add projects in Visual Studio and check them in via TFS
      > It will push that project to your repository with commits.
      How does the cloned Git repository keep up with those changes?
      > As these are latest commits after migration, so your cloned git repository will not maintain this history.
      Do you have to do another Clone?
      > Yes, there is no automated process to commit from TFS to Git, you need to do another clone.
      should you then reconfigure Visual Studio to commit changes to the new Git Repository?
      > Yes, this will solve you all above questions, as you migrated from TFS to git you should configure git repository instead of using old TFS project.
      do you just have to periodically push the cloned Git repository?
      > To push your changes to a git repository, you need to push your changes as frequently as possible. This will help you to keep track of your changes.

      I believe I answered all your question. If you still have any doubts reach out to me, I will try to answer it.
      Finally Thanks for reading my blog.

      Like

  3. Thanks Prasad! I had thought initially that git-tfs could be configured to just continually mirror/replicate your TFS model, as you work in Visual Studio. I found that when I added a new project to my TFS, that when I did a GIT Fetch on the GIT clone, it knew nothing of any new projects or change sets, since the original clone.
    So I guess what we should do here is, clone TFS to GIT, then push that to a GITHUB. Then reconfigure / remap visual studio to save changesets either directly to the new GITHUB location, or at least to the local GIT repository.

    Liked by 1 person

  4. Hi OdgeUK, I completely agree with your point. If anyone is migrating his/her code from TFS to Git, then he/she should migrate it to GIT first and reconfigure visual studio to use GITHUB for further development. In this way, you will keep track of all your changeset history for initial commit to lastest commit.

    Like

Leave a comment