Skip to content

Instantly share code, notes, and snippets.

@tmclnk
Last active April 23, 2018 15:04
Show Gist options
  • Save tmclnk/24f2479cc3842ac8fc348ccee005f662 to your computer and use it in GitHub Desktop.
Save tmclnk/24f2479cc3842ac8fc348ccee005f662 to your computer and use it in GitHub Desktop.

Introduction

You'll need a working git installation. These examples use powershell and the git-tfs package from github.

Install git-tfs

# by default powershell uses tls 1.0 :-(
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
invoke-webrequest 'https://github.com/git-tfs/git-tfs/releases/download/v0.28.0/GitTfs-0.28.0.zip' -outfile git-tfs.zip
expand-archive git-tfs.zip
set-alias 'git-tfs' "$($pwd.path)\git-tfs\git-tfs.exe"

Clone Branch

Look up branches to clone. You can only clone branches, so if it's not in this list, you can't clone it.

 git-tfs list-remote-branches http://tfs.my.org:8080/tfs

If the project you wish to clone isn't shown, then it is a folder and not a branch. You'll need to convert your folder to a branch.

git-tfs clone http://tfs.my.org:8080/tfs '$/Web Team/MyProject'

Clean Repository

If you need to clean the history of your repository, see BFG. Otherwise, you can just push back to the repository (in the next step).

Push back to VSTS

Continuing with our example, we'd have a directory containing a git repo called MyProject, so we need to set the origin and push. We'll need to make a repo in VSTS to house the newly created one. You can find instructions here. Keep the repository (no .gitignore or README.md) unless you know what you are doing.

$gitrepo='https://myorg.visualstudio.com/my-team/_git/MyProject'
cd MyProject
git remote add origin $gitrepo
git push -u origin --all

We'll see a message like Branch 'master' set up to track remote branch 'master' from 'origin'. indicating we are done.

Branches

I think you can probably get a decent approximation of your TFS branches with a series of git branch... and git-tfs fetch... commands, but I haven't tried it yet. The history might not come across in a sensible way. Comments on this are welcome...

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