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”.
Connect to it from Visual Studio 2013, Team Explorer:
Clone the repo by clicking the “Clone this repository” link:
Open up Command Prompt in the “Changes” window and “Actions:”
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
To pull down your changes from that new remote you just added:
git pull master
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
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
To track a branch from GitHub:
git branch <branch> <remotes/<remote name>/<branch>
Example: git branch FeatureBranch remotes/GitHub/FeatureBranch
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:
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.