Share →
Buffer

When I thought about moving a GitHub repository to Visual Studio Online, I assumed that Microsoft would do everything in its power to make it difficult for me to clone it. It succeeded a little – you can’t actually use just the IDE to migrate your repo; you’ll need to jump from the IDE to the Command Prompt to add a remote. But at least it works smoothly!

N.B. If you’re following along exactly, make sure that the Visual Studio Online repo that you’re migrating to is empty before you start. Otherwise, you’ll probably get some merge conflicts.

Create a new Team Project with Git as the version control type in Visual Studio Online. I’ve called mine “My GitHub Repo”.

m1

Connect to it from Visual Studio 2013, Team Explorer:

m2

m3

Clone the repo by clicking the “Clone this repository” link:

m4

m5

Open up Command Prompt in the “Changes” window and “Actions:”

m6

Then, add a remote for the GitHub repo. If we ever need to pull down commits from the repo that are located on GitHub, we can do that by pulling from the remote name rather than the long GitHub URL. The command is:

git remote add

 m7

To pull down your changes from that new remote you just added:

git pull master

 m8

And don’t forget to push your changes from your local repo up to the Visual Studio Online server (which is origin by default):

git push origin master

 m9

If you have more than one branch, you’ll have to repeat the last three steps for as many branches are in your GitHub repo that you want, with a couple of additions.

To check the branches located on your GitHub repo:

 git branch –a

branch2 github

To track a branch from GitHub:

git branch <branch> <remotes/<remote name>/<branch>

Example: git branch FeatureBranch remotes/GitHub/FeatureBranch

track branch github

Then, push ‘em on up to origin with git push origin <branch>.

Check out the result of pulling down from GitHub and pushing up to the Visual Studio Online repo:

m10

And coincidentally, I pulled a repository from GitHub that had a subtree in it, so that was cloned into our repo as well!

So there you have it, migrating from GitHub to Visual Studio Online in a nutshell.

 

 

Print Friendly
  • Stu

    What are the advantages in doing this? What does Visual Studio Online have over github?

  • Very simple. It has ALM capabilities. Visual Studio Online is basically an online Team Foundation Server.

  • Tesla

    Thank you very much. This works perfectly. Before reading this, I used to copy paste code directories. This is much more structured.

  • Sachi Williamson

    Glad to hear that this was helpful, Tesla! 🙂

  • ztheterrible

    Absolutely awesome!!!! Thanks for this!

  • João Vicente L. F. Machado

    Hi Sachi, great article! It worked fine, thanks a lot! Question: It’s OK to delete the GitHub’s repository after a successful migration without affecting the new VSO’s repository?

  • Sachi Williamson

    Hi João, glad it worked! As long as you have all of the branches (and tags) from GitHub to your local machine that you need, you should be able to delete the GitHub repository. If you’re worried about not having a backup copy of everything from GitHub, you can always clone it to your local machine: https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository#Cloning-an-Existing-Repository. You may also want to delete the reference to the remote on the local repo: https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes#Removing-and-Renaming-Remotes. The VSO repo and GitHub repo are each their own repos. Let me know if you have more questions!