From time to time there is need to replace a good technology with a not so good technology. The typical reason is a business one. I donâ€™t claim to have deep understanding of how businesses works but if you find yourself in a situation where you need to replace your best friend, your amigo, your confident Git with the womanizing, drunken lout that is TFS then this post is for you! This post describes how to import a git repo into TFS and preserve most of the history.
The first think youâ€™ll need is a tool called Git-TF which can be found on codeplex. This comes as a zip file and you can unzip it anywhere. Next youâ€™ll need to add the unzip directory to your path. If youâ€™re just doing this as a one-time operation then you can use the powershell command:
$env:Path += ";C:tempgit-tf"
to add to your path.
Now that you have that git should be able to find a whole set of new subcommands. You can check if it is working by running
You should get a list of subcommands you can runNow drop into the git repository you want to push to TFS and enter
git tf configure http://tfsserver:8080/tfs $/Scanner/Main
WhereÂ http://tfsserver:8080/tfs is the collection path for your TFS server andÂ $/Scanner/Main is the server path to which youâ€™re pushing. This will modify your .git/config file and add the following:
[git-tf "server"] collection =Â http://tfsserver:8080/tfs serverpath =Â $/Scanner/Main
Your git repository now knows a bit about TFS. All you need to do now is push your git code up and that can be done using
git tf checkin --deep
This will push all the commits on the mainline of your git repo up into TFS. Without the â€“deep flag only the latest commit will be submitted.
There are a couple of gotchas around branching. You may get this error:
git-tf: cannot check in - commit 70350fb has multiple parents, please rebase to form a linear history or use --shallow or --autosquash
You canÂ flattenÂ your branches by either rebasing or by passing git-tf the â€“autosquash flag which will attempt to flatten the branching structure automatically. Iâ€™m told that autosquashing can consume a lot of memory if there are a lot of commits in the repository. I have not had any issue but my repositories are small and my machine has 16GB of memory.
Now you have move all your source code over to TFS. Yay.
Iâ€™m not going to point out that if you keep git-tf around you can continue to work as if you have git and just push commits to TFS. That would likely be against your companyâ€™s policies.