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.