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.
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.
Thank you very much. This works perfectly. Before reading this, I used to copy paste code directories. This is much more structured.
Glad to hear that this was helpful, Tesla! 🙂
Absolutely awesome!!!! Thanks for this!
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?
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!