You have reached the blog of Keith Elder. Thank you for visiting! Feel free to click the twitter icon to the right and follow me on twitter.

Migrating Code From TFS to GitHub

Posted by Keith Elder | Posted in .Net, Git, TFS | Posted on 24-07-2013

Tags: , , ,


Before I get started I wanted to start with a disclaimer that this article is not an article about how to use git nor is it going to discuss the differences between how TFS and Git vary when it comes to source control. I’m going to assume you’ve made the decision to either try Git out for source control or you are ready to make the jump from TFS completely to using Git for source control. Trust me this really isn’t a painful process and I’m going to make it as simple as I can. Here we go.

Installing The Tools You’ll Need

Since we are migrating code from TFS to GitHub I am going to assume you already have TFS set up and installed. I’m also assuming you are using Windows and are a developer on the Windows platform. Here are two ways to get going with git. The first way is the easiest and the second way is the *geekiest* for more advanced users.

  1. Github for Windows  – A complete install to use git on windows as well as GitHub (note does not work directly with GitHub Enterprise at this time but it doesn’t matter it still makes setting up git super simple).
  2. Chocolatey  – A Machine Package Manager, somewhat like apt-get, but built with Windows in mind. This will allow one to easily install numerous packages and if you haven’t started using it yet you’ve been missing out on awesomeness.

Setting up Git Using GitHub For Windows

This is the easiest way to really set up git source control on Windows locally (unless you are already using chocolatey). Using this gives you all the tools you’ll need to start working with git and you do not have to have admin rights on your machine, everything is installed locally. Go to http://windows.github.com/ and kick off the GitHub for Windows install. Note that you do not have to create an account on GitHub to get the tools installed locally. GitHub For Windows comes with PoshGit (a nice powershell utility) and I personally find using Powershell with git from the command line the easiest way to proceed.

After installing GitHub for Windows you’ll be presented with this screen.


Login if you have a github.com account or go create one (again not completely necessary).

If you don’t want to create an GitHub account just hit cancel. After doing so click tools in the top center of the screen and select options.


In the default shell section select the shell you wish to be opened when you open the “Git Shell” from the install menu. For me personally I selected PowerShell since it comes set up with PoshGit and is faster than using a bash prompt on Windows. Plus PowerShell is just cool!



Once the option you want to use is selected press the Windows key on your keyboard and type “git shell”. This will search for the git shell so you can launch it. In Windows 8 it will look like this but you can do the same thing in Windows 7 or Windows Vista.


Launching this will launch the desired shell. You are now set up and ready to configure git (more on that later).


Setting up Git Using Chocolatey


Chocolatey is awesome and allows Windows users to easily install tons of open source software the same way Linux distributions have been doing for years. Once Chocolatey is installed it becomes trivial to install git as well as git for Team Foundation Server (TFS). To get set up with Chocolatey head over to http://chocolatey.org and follow the simple instructions. To install it all you are going to do is paste a line into a command window.

Once it is installed you can then easily install git and git tfs with the two following commands:

cinst git

cinst gittfs

These installs will look like this from a PowerShell window:



Configuring Git

Either way you decided to go on the setup above (GitHub Windows or Chocolatey) you now have git and git tfs installed. Now it is time to configure git. Git needs to know two things before we get started and those are username and email. Note I have re-printed the following information from https://help.github.com/articles/set-up-git.


First you need to tell git your name, so that it can properly label the commits you make.

git config –global user.name "Your Name Here"

# Sets the default name for git to use when you commit


Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

git config –global user.email "your_email@example.com"

# Sets the default email for git to use when you commit

Note: if you are using github.com you’ll need to use the email address associated with your account, if you are using an internal github enterprise server you’ll need to do the same

Migrating Code From TFS

Now that git is set up and configured locally we need to pull our code down from TFS locally. The purpose of the *git tfs* tool is it allows us to pull our code from TFS while also saving the commit history. If you’ve read up on git you know it is distributed which means everyone has a full copy of the repository locally.

I’ve set up a sample folder in TFS called XAmple. It only has one file in it that has been modified and checked back into TFS. It is this code base that we want to move to git.


To move this we are going to open the Git Shell. If you installed GitHub for Windows press the windows key and type “git shell” and click the icon. If you used Chocolatey open up PowerShell. Once you are at the command prompt we are going to use git tfs to pull all the code and changes from TFS down and have a git repository created for us locally.

The command to run is:

git tfs clone http://{nameofserver}:8080/tfs/SoftwareCollection $/_your_path

Here is the example from the TFS example above:


Note that we had 3 commits in TFS and we also have 3 commits showing up in our PowerShell window. Note for larger projects this can take some time to pull everything down.

Typing “git log” we can even see these commits directly from git.


Getting Our Code Into GitHub

Now that we’ve pulled our code down locally we can easily push it up into GitHub.Com or a GitHub Enterprise server. Here are the steps needed to get this going.

Before being able to push code to GitHub be sure you’ve set up an SSH key in GitHub and that it works. In other words you can authenticate and clone another repository.

The first thing we are going to do is create a repository in GitHub.


On the next screen fill in the fields. We’re going to assume this is a public repo and we’re going to add a README as well as set up the .gitignore file for CSharp (this is so files that don’t need to be committed don’t get put into the repo by accident).


We are then going to select the SSH option and copy the location in the SSH form. We’re going to then add a remote location to the repository that was created using git tfs.



Next step is to add this remote location to our local git repository so we can push and pull code to GitHub or GitHub Enterprise. I’m using our internal Git server so your settings may vary.


Next we are going to pull down the repository we created so the README and .gitignore get updated locally.


And then we are going to then push everything backup.


Now that everything is pushed up to GitHub anyone else can fork our repo, issue pull requests and we can even see the history of our files in GitHub.


And that is it! We’ve just taken a TFS repository, pulled it down as a git repository, and pushed it back up into GitHub. Once the tooling is installed this process goes pretty quickly. The thing that takes the longest is to pull the changes from the TFS server down locally, but once that is done it is just a few commands to push things back up into GitHub.

That’s it. Happy gitting!

Taking TFS Offline in Visual Studio to Work Locally With Git and PowerShell

Posted by Keith Elder | Posted in Git, PowerShell, TFS, Visual Studio | Posted on 23-03-2011

Tags: , , ,


I have been using Git (a distributed version control system) more and more lately. At work we are currently using Team Foundation Server (TFS) for our source control. Doing something as simple as checking out a file over the VPN (I work remotely) takes countless minutes out of my day. Even doing something as simple as editing a file takes time.  The seconds add up to minutes and the minutes add up to hours over time. I think I found a work around to using TFS with Git that satifies my needs. Let me know how it works for you.

Here is what I wanted to do:

  1. Use PowerShell with Git to work locally (it is faster)
  2. Put TFS in offline mode and then go online to commit back to TFS, then go back offline

Sounds simple enough but the way TFS works is when you open a solution it tries to connect to TFS. This is the only way to make TFS think you are offline. It almost means you have to disconnect your network cable, load up a solution, wait and let it figure out it is offline. Not optimal.

I got to looking around for a way to just set TFS in offline mode. After much looking around I found nothing, nothing at all. Some more searching I found a VS2010 extension that adds a “Go Offline” option in the File->Source Control menu. Sweet! Here is the link to the extension.


Here is how it looks after installed.


Clicking this takes the solution offline. What does this mean? It means when I need to move a file around or change a file, or edit a file things are instant locally (the way they should be).

Locally I’m using Git to do my check ins, branching, etc. Once I’m done I take the soluction back online by connecting to TFS and then commit the changes back to TFS (or shelve them if I need to share with a team member). I’m currently using PowerShell with GIT and some PowerShell prompt coolness with Git too.  To do this I’m using posh-git (PowerShell environment for Git). Here’s a sample screen shot (and yes the Git branches are in the prompt along with some stats!).


You’ll see the word “Sonic” in blue text. That is the current branch I’m on. The numbers in the prompt are how many files are added, modified or deleted since the last commit. Easy quick and elegant. I’m digging it.

I haven’t been using this very long so I *may* run into some weird situations, if I do I’ll update this post. Let me know what you think if you’ve been using Git with TFS and pass along any tips! Happy coding.