Migration of Tfs Source Code using History to Git(Stash, Bitbucket) Using Powershell

#clone the TFS repository to a folder which you would like to keep for pushing to stash[Ensure Deep is mentioned to get the whole history]

 

C:\TFSGITMigration\xxx>”C:\Git-TF\git-tf-2.0.3.20131219\git-tf” clone http://TFSURL:8080/tfs $/CVR-TFSPROD/CT_MAIN –deep

 

#remove the *.vssscc

Get-ChildItem ‘C:\Sxxx\Trunk’ -Include *.vssscc -Recurse | foreach($_) { Remove-Item $_.FullName -WhatIf}

 

#remove the *.vspscc

Get-ChildItem ‘C:\XXX\DEVELOPMENT’ -Include *.vspscc -Recurse | foreach($_) { Remove-Item $_.FullName -WhatIf}

 

#this will give the list of sln files

PS C:\CAB> Get-ChildItem ‘C:\XXX\DEVELOPMENT’ -Include *.sln -Recurse | foreach($_) { $_.FullName}

 

#remove the source control bindings from the solution files.

Get-ChildItem ‘C:\XXX\DEVELOPMENT’ -Include *.sln -Recurse | foreach($_) { C:\Software\ReplaceSourceControlBinding.ps1 -SolutionFile $_.FullName } > C:\log.log

 

 

#Manually create a repository under the project key CVRCAT with name cvr-core to upload the files in stash

 

Git add .

Git commit –a –m “removed unwanted files related to TFS souce control”

 

#this adds a remote repository

 

git remote add originprod http://TESTURL:7990/scm/cvrcat/cvr-core.git

or use below naming convention for remote shortform

 

 

git push originprod master or development

 

 

To continue with the development on TFS branch…

 

Execute the command line in cmd

“E:\Software\git-tf-2.0.3.20131219\git-tf” pull  –deep –rebase [It will pull the changeset and merge it, however revert the changes you have done in your local repository]

 

Also check if rebase stopped in between due to conflict in file

Remote the conflict manually

Git add “File name whole path”

Git commit –m “remove the source control binding”[basically you need to commit the files again due to rebase]

Git rebase  –continue.

 

Git push originprod master

 

To reset the head by one.

 

First be on master

git reset –hard HEAD~1 [It will reset the head by one]

 

git push originlab(prod) master –force [force is necessary to force the upload to stash]

 

If for some reason stash failed and we need to move back to TFS, by moving the stash changes back to TFS… Below is the command line..

 

“E:\TFS-GIT\git-tf-2.0.3.20131219\git-tf” checkin –bypass(for bypassing gated builds)

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *