How to sync branches between GitHub and Visual Studio Team Services (VSTS)

To enable branch sync between GitHub and Visual Studio Team Services (VSTS):

  • Create a build definition in VSTS
  • Save the PowerShell script below in a file
  • Add a PowerShell task and point to the PowerShell script from the previous step
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 }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s