Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mirror Github and VS Online?

I have my code in a private Github.com repo, and also in a private Microsoft Visual Studio Online git repo. Now I want to mirror / sync them automaticly. So that when I checkin something to Github, it also pushes to VS Online, and vice versa.

I know how to do this 'client-side', by adding extra push-remotes to my local repo. But is it possible to do this 'server-side' too? Using Github Webhooks or something from Microsoft?

Because otherwise I must instruct everyone who wants to work on the code, to add both remotes, or am I wrong?

like image 988
Maestro Avatar asked Mar 30 '15 14:03

Maestro


People also ask

Can you link VS Code to GitHub?

To get started with the GitHub in VS Code, you'll need to install Git, create a GitHub account and install the GitHub Pull Requests and Issues extension. In this topic, we'll demonstrate how you can use some of your favorite parts of GitHub without leaving VS Code.


1 Answers

  1. Add GitHub service endpoint to your VSTS (Setting > Service)
  2. Create an Empty build definition with GitHub repository in your VSTS
  3. Select Repository tab and specify Connection, Repository and Default branch. (set Clean to true, clear source directory)
  4. Select Triggers tab and check Continuous integration, Batch changes and specify Branch filters
  5. Select Options tab and check Allow Scripts to Access OAuth Token

  6. Select Build tab and add a PowerShell task with the following script to sync all branches.

git branch -r | findstr /v "\->" | ForEach-Object {$br=$_.TrimStart(); git branch --track $br.TrimStart("origin/") $br} $repoName = "$env:BUILD_REPOSITORY_NAME".split('/')[1] $repoUri = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI".Substring(8)+ "_git/$repoName" git remote add vsts "https://$env:SYSTEM_ACCESSTOKEN@$repoUri" git branch -r | findstr /v "\->" | ForEach-Object { $br=$_.TrimStart(" origin/"); git push -u vsts $br }

like image 63
maxisam Avatar answered Sep 30 '22 22:09

maxisam