Migrate code from Team Foundation Version control (TFVC) to Git
You can perform the code migration by using an utility called
TFS-Git. This is two-way cross platform tool used for migrating TFVC
repositories to git. It can update TFS with changes committed to git as
well. It works similar to git-svn tool.
Two things are important for successful code migration.
1. actual code base - each and every files is migrated
2. change sets history - this includes entire history.
Let us get into the crux of our migration.
Pre-requisites:
1. Tfs-git. (Download from
here)
2. git client.
Configuration steps:
1. Extract git-tf zip into local hard drive, lets say in C:\ drive, after extracting you should see a folder called C:\git-tf
2. Add c:\git-tf to PATH env variable so that you can execute it from anywhere
3. Go to command prompt, execute git-tf. You should see some commands. This tells git-tf is successfully installed.
Migration:
Migration is actually performed in three phases.
1. Clone - download project files from TFVC repository by cloning into local machine.
2. Prep - Set up and qualify downloaded projects for uploading git remote repository.
3. Push - Execute push command for uploading into git remote repo
Steps:
1. Create a remote Git repo(target) in VSTS or where ever you are hosting Git repos.
2. Go to command prompt, execute the below command for cloning the TFVC repo locally .
git-tf clone http://<TFS Server Name>:Port/tfs/<CollectionName> "$/TeamProjectName" C:\MyProject –-deep
--deep means it will include history for the repository.
3. Now entire project repo is downloaded in your local machine C:\MyProject.
We can upload into Git repo created in step 1 above. we need to add remote git repo.
git remote add origin <git_url>
where git_url could be --> https://MyVSTS.com/DefaultCollection/MyGitreponame/_git/projectRepoName
4.
git push origin master
or git push head:branchname ---> you can execute this command if
you like to migrate to a different branch and didn't want to migrate to
master branch.
This should push code from your local machine into remote Git repo.
How to verify?
It is recommended to verify two things to make sure we have successfully migrated.
1. Comparing the number of commits between TFVC and Git
Go to command prompt, execute the below command.
git log --oneline
This gives list of total commits in that project in one line. Count
this total commits and go to TFVC, count the total number of change sets
by going into that project , Code --> explorer --> History.
Both numbers should match.
2. Compare the total number of files in TFVC and Git(optional step)
Go to TFVC, select the project. Download as a zip. Once downloaded,
right click on the folder to see total number of files and folder. This
should match with what we pushed into Git.
Notes:
- Depending on size and volume of source TFVC repository, cloning may take considerable amount of time.
- Avoid doing migration when connected on VPN. It may slow down cloning depending on internet bandwidth.
That's it! Happy Migration :)