Sync Azure Devops repo with GitHub repo

Dileep Veldi
3 min readOct 7, 2020


Sync Azure Devops Repository with GitHub Repository

Let’s say you have a repository in Azure DevOps and you want to keep that in sync with another repository in GitHub, so that you can integrate GitHub with other tools or services. With this you can still manage everything from Azure DevOps like you do today and no additional training is required.

So are you looking for syncing Azure repos with Github enterprise repos? Or are you planning to design a pipeline solution, so that all the file changes pushed to Azure repository (primary) should be reflected on the Github repo (secondary) also?

To complete this tutorial, you need following
1) GitHub Personal Access Token
2) Azure DevOps Personal Access Token
3) Existing Azure repo with files
4) New empty GitHub repo
5) Azure build pipeline with a powershell inline task

1) To the existing CI pipeline or new pipeline, add pipeline variables as secret variable

name ‘AzureDevOps.PAT’ (with value as your Azure DevOps PAT) and name ‘Github.PAT’ (with value as your GitHub PAT)

2) Add a Powershell task

3) Add this script as inline script

# Write your PowerShell commands here.
Write-Host ' - - - - - - - - - - - - - - - - - - - - - - - - -'
Write-Host ' reflect Azure Devops repo changes to GitHub repo'
Write-Host ' - - - - - - - - - - - - - - - - - - - - - - - - - '
$stageDir = '$(Build.SourcesDirectory)' | Split-Path
$githubDir = $stageDir +"\"+"gitHub"
$destination = $githubDir +"\"+"<azure-repo-name>.git"
#please provide your username
$alias = '<userName>:'+ "$(Github.PAT)"
#Please make sure, you remove https from azure-repo-clone-url
$sourceURL = 'https://$(AzureDevOps.PAT)@<azure-repo-clone-url>'
#Please make sure, you remove https from github-repo-clone-url
$destURL = 'https://' + $alias + '@<github-repo-clone-url>'
#Check if the parent directory exists and delete
if((Test-Path -path $githubDir))
Remove-Item -Path $githubDir -Recurse -force
if(!(Test-Path -path $githubDir))
New-Item -ItemType directory -Path $githubDir
Set-Location $githubDir
git clone --mirror $sourceURL
Write-Host "The given folder path $githubDir already exists";
Set-Location $destinationWrite-Output '*****Git removing remote secondary****'
git remote rm secondary
Write-Output '*****Git remote add****'
git remote add --mirror=fetch secondary $destURL
Write-Output '*****Git fetch origin****'
git fetch $sourceURL
Write-Output '*****Git push secondary****'
git push secondary --all
Write-Output '**Azure Devops repo synced with Github repo**'
Set-Location $stageDir
if((Test-Path -path $githubDir))
Remove-Item -Path $githubDir -Recurse -force

4) Now save and queue pipeline.

Helpful article



Dileep Veldi

2x Azure Certified | Experienced Cloud Solutions Developer and DevOps Engineer