Migrate repository from TFS to Github
Migrate repository from TFS to Github
What you’ll need before you start
- Name of old TFS repository
- Version number within the old TFS repository you want to migrate history from (important with big, old projects)
- Git-TF (see installation instructions below)
- New Github repository
Install Git-TF
If you don’t already have Git-TF, you can either use Chocolatey with cinst Git-TF
, or download it manually from the Git-TF project page.
Create a new Github repository
Log into Github and create a new repository with the name of project. This may be different from the old TFS name as some repository naming conventions have changed. NB. You may need someone else to do this for you if you don’t have permission.
Clone the TFS repository as a Git repository
Within your git workspace (typically, C:\Git
), type the following command (and when promted use the administrator’s credentials):
git tf clone --deep http://my-tfs:8080/tfs/Tfs {src-repo} .
NB. {src-repo} is the TFS repo path, but with the /
changed to \
. If you fail to do this, you may get a git-tf: A server path must be absolute.
But, if the repository is too big (too many commits), then you may also do:
git tf clone --shallow --version={n} http://my-tfs:8080/tfs/Tfs {src-repo} .
git tf pull --rebase --deep
E.g. For SAPI, the shallow command looked like:
git tf clone --version=69919 --shallow http://my-tfs:8080/tfs/Tfs $\SAPI\Main .
git tf pull --rebase --deep
NB. If you get an error like Unable to find a required JAR: C:\ProgramData\chocolatey\lib\Git-TF\Tools\git-tf-2.0.3.20131219/lib/com.microsoft.gittf.client.clc-*.jar does not exist
, follow the instructions at http://stackoverflow.com/questions/33915987/git-tf-unable-to-find-required-jar
Prepare to ‘Gitify’ and ‘NuGetify’ the project
First, copy over the following Git files from the FMP project into the new Git project folder:
.gitignore
.gitattributes
Then, for the solution folder, copy over into a new .nuget
folder from the FMP project:
.nuget\nuget.config
Clean the solution
Remove *.vs{aa}cc
files and the packages
folder.
Open the solution in Visual Studio:
- Ensure it doesn’t have any links to TFS; if it does, remove them
- Force a save by creating a new folder, saving the solution and then deleting the folder and re-saving the solution
Incorporating NuGet into the solution
- Add the
.nuget
folder into the solution - Build the solution
Clean the Git repository
Run the following script to remove the packages
folder from the repository:
git filter-branch --index-filter "git rm -r --cached --ignore-unmatch packages/" --prune-empty --tag-name-filter cat -- --all
Push to Github
Set the Git remote to that of the Github repository url, and then push to Github by running the following:
git remote add origin {git-repo-link}
git push origin master --force
Update the TeamCity build to use Git, rather than TFS
- Go to the TeamCity project and choose Edit Project Settings
- Then choose VCS Roots
- For each item in the list perform the following:
- Change Type of VCS to Git
- Change Fetch URL to that of the Github repository (using the format git@github.com:findmypast/{repository}.git)
- Change Authentication method to Uploaded Key
- Change Uploaded Key to teamcity-fmp
- (Click Advanced Settings if necessary)
- Tick Convert line-endings to CRLF
- Hit the Test connection button
- Hit the Save button
Update TeamCity to restore NuGet
- Within the TeamCity project choose Edit Project Settings
- Then choose Build Steps
Add build step to restore NuGet
- Click Add Build Step
- Choose Runner type of NuGet Installer
- Click Show advanced options
- Set Step name to that of Restore NuGet packages
- Set Path To Solution File by clicking the tree dropdown to the right and selecting it
- Set Package Sources to the urls contained within
.nuget\nuget.config
-
Click Save
- Hit Reorder build steps and move the newly created step to the top of the list and click Apply