如何同步 Github 和 Azure DevOps 存储库?

rik*_*520 7 github azure-devops azure-pipelines

我有两个存储库,第一个位于 Azure DevOps 上,第二个位于 GitHub 上。我想更新 GitHub 存储库,以便在两个存储库上拥有相同的代码。如何在不手动复制源代码的情况下做到这一点?

Hon*_*Ooi 9

您可以包含一个运行 git 的管道步骤,以复制存储库。像这样的东西:

steps:
- bash: |
    git push --prune https://$(GITHUB_PAT)@github.com/$REPO_NAME \
        +refs/remotes/origin/*:refs/heads/* +refs/tags/*:refs/tags/*
  displayName: 'Copy to Github'
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
Run Code Online (Sandbox Code Playgroud)

(复制自https://github.com/Azure/AzureStor/blob/master/azure-pipelines.yml,稍作修改)


Lan*_*SFT 5

如何在不手动复制源代码的情况下做到这一点?

据我所知,Azure Devops Repos 本身没有这样的功能来监视 git 存储库并自动保持这两个存储库同步。

不过我认为有一些解决方法可以满足您的要求。您可以查看此博客,了解有关如何在管道中使用 git 命令来执行上述操作的详细信息。此外,专为 Azure DevOps扩展设计的免费 G​​it 工具synchronise one Git Repository with another可能会对您的场景有所帮助。

此外:如果您确实喜欢此同步功能,请随时在 Azure Devops 的用户语音论坛中提交功能请求。产品团队会考虑您的想法,如有更新会给予回复。