" MicromOne: Mirror GitHub Repository to Azure DevOps Repos via Pipeline

Pagine

Mirror GitHub Repository to Azure DevOps Repos via Pipeline


Create a PAT in Azure DevOps

  1. Azure DevOps → top right User Settings → Personal Access Tokens
  2. Click New Token:
    • Name: mirror-pat
    • Scope: Code → Read & Write
  3. Copy the generated token
Step — Add PAT as a Secret Variable in the Pipeline
  1. Azure DevOps → Pipelines → select your pipeline → Edit
  2. Click Variables → New variable:
    • Name: AZURE_PAT
    • Value: paste your PAT
    • Check: Keep this value secret
  3. Save
Step — Add azure-pipelines.yml to your GitHub repo
Example configuration:
trigger:
  branches:
    include:
      - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
  persistCredentials: true

- script: |
    git push --force https://$(AZURE_PAT)@://azure.com<ORG>/<PROJECT>/_git/<REPO> HEAD:main
  displayName: 'Mirror to Azure Repos'
Replace <ORG>, <PROJECT>, and <REPO> with your specific values.
How it works
  1. GitHub repo (source): Pushing to main triggers the pipeline.
  2. Azure Pipelines: Clones the GitHub repo and uses git push --force to copy commits.
  3. Azure Repos (mirror): Receives the exact copy of the repository.
  • GitHub is the source of truth.
  • Azure Repos acts as a read-only mirror.
Troubleshooting
  • Authentication failed: Usually caused by an incorrect $(AZURE_PAT) variable.
  • Rejected push: Ensure the --force flag is included in the git push command.
  • Command not found: Often a syntax error in the YAML script block.
Notes
  • --force is only safe if no one is pushing changes directly to Azure Repos.
  • The only URL required is the destination Azure Repos URL.