10

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?

Maestro
  • 9,046
  • 15
  • 83
  • 116

2 Answers2

2
  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 }

maxisam
  • 21,975
  • 9
  • 75
  • 84
  • That's surprisingly clever, but why not just point your build task at a GitHub repository? (This is a serious question, not a troll, I suspect that you're solving a problem that I don't yet see.) – Edward Thomson Feb 24 '18 at 00:05
  • I actually do. There are some benefits. First, you have VSTS as a backup. Second, you can utilize more feature in VSTS for stakeholders. Why don't we just use VSTS? I don't know. Some people like Github interface. If you are in a team, sometimes you need to try to find a way to make things work instead of asking why. BTW, I even learn how to use powershell only to solve this problem. – maxisam Feb 24 '18 at 00:18
  • Sorry, to clarify: I wasn't asking why to move from GitHub+VSTS to pure VSTS - VSTS lets you build out of GitHub repositories natively. (You don't need to use the Git support in VSTS to build in VSTS.) – Edward Thomson Feb 24 '18 at 00:22
  • Again, I do point my build task against Github. Doing this is NOT for running build. It is for other features that can refer to code nicely in VSTS. – maxisam Feb 24 '18 at 00:32
1

The only thing we can do right now is use Zapier, which does have a free plan. As it stands, from what I can find, there isn't a way to sync the two together through a Web hook or any other means.

I'll keep searching for you and if I find anything different I will update this answer.

William Hodges
  • 661
  • 10
  • 24