Skip to content

Instantly share code, notes, and snippets.

@AAugustine
Created March 29, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AAugustine/268f7eed2043de24526b9254a0881579 to your computer and use it in GitHub Desktop.
Save AAugustine/268f7eed2043de24526b9254a0881579 to your computer and use it in GitHub Desktop.
TFS to Git migration strategy

TFS to Git migration strategy

Pulling history from TFS is time consuming. Please be patient and keep an eye on your migration.

Install Git-TFS with Chocolatey

We need to install the tooling git-tfs on the local machine to help convert data from the TFS format to Git.

  • Go to Chocolatey Install
  • Follow instructions to install Once you have installed, run command to install git-tfs
  • choco install gittfs

Clone the git-tfs utility down (instead of Chocolatey; Optional)

Navigate to:

  • Releases
  • Select the latest full release
  • Unzip the binary on your local machine
  • Set in a location that is easy to path
  • Open GitBash shell and set the path:
    • set PATH=%PATH%;\GitTfs-Version
  • Or you can set in your full path location if easier to achieve
  • Validate that the tool is pathed correctly
    • git tfs help
    • You should see the standard help page for the tooling

Clone the TFS repository

You can follow the documentation in the main repository:

  • Migration Doc You will need to create a small workspace on your local machine to do the clones and cleanups away from your development environment.

Clone everything

  • git tfs clone https://TFS-Server-Name:443/tfs/Collection $/project/trunk . --branches=all
    • This is the longest and most expensive; it also could have the most errors

Only merged branches

  • git tfs clone https://TFS-Server-Name:443/tfs/Collection $/project/trunk . --branches=auto
    • This is a cleaner version with some of the history

Master branch only

  • git tfs clone https://TFS-Server-Name:443/tfs/Collection $/project/trunk . --branches=none
    • Only history for what is in master; this clean and efficient

Single changeset only

  • git tfs clone https://TFS-Server-Name:443/tfs/Collection $/project/trunk . --changeset=3245
    • We're really reaching for some history at this point... going off the beaten path... This is not advisable

Latest changeset only

  • git tfs quick-clone https://TFS-Server-Name:443/tfs/Collection $/project/trunk .
    • Just the latest changeset that was pushed into master

Clean the repository

You can now clean the commits, remove trash, etc

  • git filter-branch -f --msg-filter "sed 's/^git-tfs-id:.*$//g'" -- --all
  • Delete the git folder
  • rm -rf .git/refs/original
  • Add optional gitignore file:

Create empty GitHub repository

Log into GitHub.com and navigate to your Organization. You will need to create a repository that is ready for the initial push

  • Select to create repo and do NOT initialize with README.md or .gitignore
  • Select the naming scheme you would like to follow and name the repository
  • It will give you the origin and push commands that you need to run on your shell to push the code to GitHub

Example of pushing to GitHub

echo "# RepoName" >> README.md
echo "TFS History for this repo can be found at: [RepoName](tfs.com/path) " >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:<YourOrganization>/<RepoName>.git
git push -u origin master

Prepare workspace for another migration

  • Change directory into your migration folder and run the following commands
    • rm -rf * .git .nuget
  • Verify the folder is clean
    • ls -la
  • If it the folder is clear, you can start the next repository migration

TFS to Git utilizing TFS 2017+ or Azure DevOps

If the customer is utilizing TFS 2017+ or greater, or is utilizing Microsoft Azure DevOps, then they have the opportunity to migrate their source code data from tfsvc to git utilizing the SCM tool. The short comings to this method:

  • The built in will migrate the source for up to 6 months backwards in history
  • The built in will only migrate the master branch

If this is acceptable to the end user, then they can follow the information outlined below:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment