Moving an existing Git Repository to TFService/TFS 2013

In this post, I will describe how you can easily ‘move‘ an existing Git Repository (like GitHub, BitBucket,..) to Team Foundation Service or Team Foundation Server 2013. As you might know, TFS Service and 2013 offer Git support as DVCS solution. You can find some additional information about the Git story on the great blog post by Brian Harry!

So, you have an existing Git Repository, and you want to ‘move’ it to TFS? Well, compared to a migration from one server using TFSVC (a topic I blogged about recently) to another server (like TFService), moving a Git repo is a piece of cake! In fact, you have two options

The command-line way

Let’s start with the easy, command-line way. We will ‘replace’ the remote, with the remote of TFService/TFserver. The sources will still be on the same location! All you need are some commands. First, list your existing remote alias for your Repo. Using the Git Shell, browse to your Git repo and enter the command:

git remote -v

You will now see your existing remote alias. We can remove this remote using the command:

git remote rm origin

Now we can add the new remote for the origin (the one from the TFService/TFServer). Replace your subscription, team project name en Git repo name:

git remote add origin https://vanwynsberghea.visualstudio.com/DefaultCollection/GitRepo/_git/MyRepo

The last step is to push it to the new remote:

git push -u origin --all

You will now have something like:

01

Note that you need to have ‘Alternate credentials‘ enabled if you’re using TFService. You can enable this by clicking on your name on the top right corner of the Web Access and select ‘My Profile – Credentials‘.

The Visual Studio way

The first option is really easy, but there’s another way, using Visual Studio. This approach keeps your original repo as-is, so you can still work on the ‘old’ repo against your old remote. (which is not the case using the first approach). This is how: First, connect your Team Explorer to your Git Team Project on TFService/TFServer. You will see a small ‘folder icon‘ next to the name of your Team Project.

02

Open the Team Project, and clone the repository to your local file system:

03

Great, so now you have a clone of the repository on your local file system. The only thing left is ‘pulling‘ your old repo (which is also somewhere on your file system) to the location of your new repo. Do this by browsing to the ‘Commits‘ section of Team Explorer, select ‘Actions – Open Command Prompt‘. This will open a command prompt scoped to your Git folder:

04

In that window, type the command (replace the location):

git pull C:\Source\LocationOfYourOldRepo

Once that command has finished his job, go back to Team Explorer, and you will see all the commits from your old repo. Click ‘Push‘, and you’re done!

05

That was easy, no? Have fun!

Written by
Alexander Vanwynsberghe
Join the discussion

12 comments
  • Thanks for this post. Note, however, that when using the command line method, after removing origin, you can’t set the origin url as you describe, as origin no longer exists. Replace set-url with add in the third command, and it all works OK.

  • Thanks for the post, Regarding the visual studio way, does the pull command need to look like “git pull file:///C:/SOURCE/LOCATIONOFYOUROLDREPO”

  • Hm, it seems I have still to create a repro first in Visual Studio 2013 before I can push my local repro to the TFS 2013 Express server. Is there a way to create a new project/repro from command line?

  • Already moved some repos using exact the same steps but now for the last step “git push -u origin –all” I get:

    error: src refspec –all does not match any.
    error: failed to push some refs to ‘repourl’

  • Very cool and a great guide. Thanks for posting this. We were piloting GitHub and now looking to move to TFS. I have the GitHub repo now on TFS…the challenge I’m faced with is that we have folks still committing to GitHub and I need to setup a one way mirror to TFS so the commits from GitHub are in sync over to TFS. At some point we will do a complete switch to TFS so there will only be commits in the TFS repo.

Menu

Alexander Vanwynsberghe

Belgium-based entrepreneur. Into technology, innovation and a bit of cycling and running too. Evangelist for everything related to smart-tech.