Configuring Bi‑directional Sync Between GitHub and VSTS Using CI Pipelines
This guide explains how to set up bi‑directional synchronization between public GitHub repositories and private VSTS (Azure DevOps) repos using VSTS CI pipelines, covering configuration steps, command‑line tasks, token handling, and common synchronization scenarios.
GitHub is the global hub for open‑source code; for example, there are over 320,000 active JavaScript repositories. Many developers share parts of their code on GitHub to increase visibility, attract collaborators, and meet other developers.
Free repositories on GitHub are public only, so private projects cannot be shared for free. You can either upgrade to a paid plan for private repos or use Microsoft’s free enterprise‑grade service Visual Studio Team System (VSTS), which provides private Git repositories.
By combining GitHub’s public repos with VSTS’s free private repos, you can build an internal‑external development platform that controls which code is open‑source while still accepting community contributions. Typical scenarios include:
Two‑way synchronization of the private repo’s master branch with the public repo’s master branch, enabling release sharing and pull‑request acceptance.
Two‑way synchronization of a specific private branch with the public repo’s master branch, allowing selective release sharing and later merging back into the private master after internal review.
Separate publishing of private and public releases.
Both automatic and manual synchronization options.
Creating CI on VSTS to Configure Synchronization
VSTS’s CI engine natively supports GitHub and its own Git, making it easy to establish a sync mechanism.
1. Create a sync job from VSTS to GitHub
Create a build definition using the “Empty” template and select a VSTS repo as the source.
Add two “Command line” tasks with the following commands:
Git pull https://github.com/ups216/vsalm-hols.git master
Git push https://$(githubtoken)@github.com/ups216/vsalm-hols.git head:masterThe second command uses the $(githubtoken) variable. Generate a Personal Access Token on GitHub and bind it to the build definition so the token value remains hidden during execution.
The lock icon in the screenshot indicates that VSTS stores the key encrypted, preventing users from seeing the raw token.
2. Create a sync job from GitHub to VSTS
The configuration is reversed: first create a build definition that pulls code from GitHub.
Then run the following two commands:
Git pull https://$(vststoken)@almnetworks.visualstudio.com/DefaultCollection/_git/vsalm-hols master
Git push https://$(vststoken)@almnetworks.visualstudio.com/DefaultCollection/_git/vsalm-hols head:masterBoth commands use the $(vststoken) variable because the VSTS repo is private and requires authentication for read and write operations.
After configuring the above, you can test the bi‑directional sync; a 5‑minute video demonstration is provided in the original source.
The simplest configuration synchronizes the master branch; to sync specific branches, adjust the Git commands accordingly.
Please follow the WeChat public account devopshub for more DevOps integration information.
DevOps
Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.