Mirroring Git Repositories

Nevin Cansel Efendioglu
KoçSistem
Published in
4 min readMar 13, 2022

--

In the development world, repositories are treasures that we have because we keep all of our works in there. However, sometimes we need to use more than one repository and there might be a requirement that synchronizing two repositories.

We had the exact same situation for the one of our projects and this question popped into my mind. How can i synchronize my repositories which are in different locations?

I wrote a Powershell script to mirror two repositories and it worked but what if it would be an extension and everyone who needs could use that?

That would be awesome and here is the result!

What does this extension do?

This extension synchronizes repositories by running on Azure DevOps Pipelines.

You can find the extension in Visual Studio Marketplace.

How does it work for Cloud?

These are source and destination repositories which are located in Github and Azure DevOps Cloud.

Source: Github

Destination: Azure Cloud

Fields of the extension is set to Cloud as default.

I added personal access tokens as variables.

Now, I can run the pipeline.

Warning: Since the extension is written in Powershell, it must be run in Windows Agents.

My pipeline finished successfully.

Now, let’s check the destination repository.

It worked!

How does it work for on-prem?

Create personal access token for destination and source repositories. I will synchronize Azure Repos on-prem and cloud as an example.

These are source and destination repositories.

Source: Azure On-Prem

Destination: Azure Cloud

This time, I will use classic pipeline.

I deselected the first option because my source is not on Cloud.

Username, password and PAT are saved in variables.

Now, I can run the pipeline.

Now, let’s check the destination repository.

It worked again!

Recommendations

  • If you create the pipeline in your source repository, you can add trigger to pipeline to synchronize the destination repository if there is a new commit.
  • You can schedule your pipeline to sync your repositories in a designated period.
  • Force Push and Create Branch permissions for repositories might be necessary in Azure DevOps.

--

--