Using Visual Studio Online with GitHub

Visual Studio Online (VSO) requires your Git repository to be hosted in the VSO cloud. In other words, you cannot specify an URL such as https://github.mycompany.com/product/project.git, even if you want to use your existing Git repository.

One solution is to set up the local repository to track two remotes. The following are the steps, using Git Bash commands.

First, you add Visual Studio Online as the second remote. Go to the CODE page of your project in VSO, click the 'Clone' link. You will see the Git URL. Copy and paste it into the command similar to the following.

$ git remote add vso https://mycompany.visualstudio.com/DefaultCollection/_git/project

Now you should see two remotes.

$ git remote
origin
vso

If you open the .git\config file, you should see two remote sections.

...
[remote "origin"]
url = https://github.mycompany.com/product/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[remote "vso"]
url = https://mycompany.visualstudio.com/DefaultCollection/_git/project
fetch = +refs/heads/*:refs/remotes/vso/*
...

Before you can push the repository to VSO using an external tool like Git Bash, you need to enable alternative credentials. From the same popup you get the Git URL, click the 'Profile' link. In the USER PROFILE dialog, select the CREDENTIALS tab. You can use the same primary user name, which is the Microsoft account (hotmail, live, outlook) you use to sign in to VSO. But you can set a different password.

Then execute the following command, using the credential you just set up.

$ git push -u vso --all
Username for 'https://mycompany.visualstudio.com': myname@live.com
Password for 'https://myname@live.com@mycompany.visualstudio.com': <password>
Counting objects: 459, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (311/311), done.
Writing objects: 100% (459/459), 20.45 MiB | 155 KiB/s, done.
Total 459 (delta 274), reused 255 (delta 132)
remote: Analyzing objects (459/459) (113804 ms)
remote: Storing pack file and index...  done (1359 ms)
To https://mycompany.visualstudio.com/DefaultCollection/_git/tests
 * [new branch]      master -> master

Branch master set up to track remote branch master from vso by rebasing.

Now your local repository is tracking two remotes.

Making changes to both repositories and keeping them in sync can be costly. Consider establishing some policy. To keep it simple, for example, you may want to only push changes to your existing GitHub repository, and just pull from the VSO repository.

You may ask, why bother. Well, there're certain things that require us to check code into VSO. For example, load testing. And we don't necessarily want to move away from GitHub. This kind of bridges the gap.




Comments

Popular posts from this blog

Viewing test results and artifacts captured with 'Test & Feedback' in Azure DevOps

Changing default language in Visual Studio

The Web Development Puzzle