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:
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.
Open the Team Project, and clone the repository to your local file system:
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:
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!
That was easy, no? Have fun!