- Azure DevOps → top right User Settings → Personal Access Tokens
- Click New Token:
- Name: mirror-pat
- Scope: Code → Read & Write
- Copy the generated token
Step — Add PAT as a Secret Variable in the Pipeline
- Azure DevOps → Pipelines → select your pipeline → Edit
- Click Variables → New variable:
- Name: AZURE_PAT
- Value: paste your PAT
- Check: Keep this value secret
- Save
Step — Add azure-pipelines.yml to your GitHub repo
Example configuration:
Example configuration:
Replace
<ORG>, <PROJECT>, and <REPO> with your specific values.How it works
- GitHub repo (source): Pushing to main triggers the pipeline.
- Azure Pipelines: Clones the GitHub repo and uses
git push --forceto copy commits. - 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
--forceflag is included in the git push command. - Command not found: Often a syntax error in the YAML script block.
Notes
--forceis only safe if no one is pushing changes directly to Azure Repos.- The only URL required is the destination Azure Repos URL.
