将 Git 存储库与 VSTS 中集成的 Git 同步
Sync Git repository with the Git Integrated in VSTS
我想知道有什么方法可以将 Git 存储库与 Git Integrated with VSTS 同步。例如,假设我有一个 Git 存储库“https://github.com/test/TestProject" and I have imported this Git repo in VSTS. Now my VSTS Git repository URL say "https://testuser.visualstudio.com/test/_git/TestProject”。
我想同步这两个东西并保持更新。就像如果我在直接 Git 存储库中进行任何更改,它应该反映在 VSTS Git 存储库中。即使是通过任何构建定义或任何拉取请求,也没有问题。
有人可以帮助我吗?
您需要 webhook (ion GitHub) or a service hook(在 Visual Studio)才能接收推送事件。
您还需要编写并安装一个侦听器,它将侦听由 web/service 挂钩作为 JSON 有效负载发送的推送事件(请参阅 GitHub one, or the Visual Studio one)。
Visual Studio integrates with external services as well,它们有自己的侦听器。
从一个远程仓库接收到推送事件后,您可以从中拉取,然后推送到另一个。但请注意,在从一个仓库推送到另一个仓库时,同一分支上的任何并发开发都可能导致冲突。当在每个 repo 上使用不同的分支时,这种方法有效。
也可以通过创建构建定义从 GitHub 中提取更改,然后将更改推送到 VSTS Git 来实现。以下是供您参考的步骤:
- Deploy your own build agent 然后生成 SSH 密钥。
- 为你的 VSTS Git Repo 启用 SSH Authentication 这样你就不需要在你的构建定义中输入用户名和密码。如果您想使用备用凭据,可以跳过第 1 步和第 2 步。
- 创建构建定义和 select GitHub 作为存储库。
- 在构建定义中启用 "Continuous integration (CI)" 选项,以便在 GitHub 中提交新更改后立即触发构建。
- 在您的构建定义中添加一个 PowerShell 脚本以将 VSTS Git 添加为远程并将更改推送到它。
现在,当您在 GitHub 中提交更改时,您应该会看到构建被触发,然后构建将从 GitHub 中提取更改并将其推送到 VSTS Git。
供您参考的 PowerShell 代码:
git remote add vstsg ssh://vstsaccount@vstsaccount.visualstudio.com:22/VSTSProjectName/_git/VSTSGitRepoName 2>&1 | Write-Host
git checkout -b master 2>&1 | Write-Host
git push vstsg master 2>&1 | Write-Host
我想知道有什么方法可以将 Git 存储库与 Git Integrated with VSTS 同步。例如,假设我有一个 Git 存储库“https://github.com/test/TestProject" and I have imported this Git repo in VSTS. Now my VSTS Git repository URL say "https://testuser.visualstudio.com/test/_git/TestProject”。
我想同步这两个东西并保持更新。就像如果我在直接 Git 存储库中进行任何更改,它应该反映在 VSTS Git 存储库中。即使是通过任何构建定义或任何拉取请求,也没有问题。
有人可以帮助我吗?
您需要 webhook (ion GitHub) or a service hook(在 Visual Studio)才能接收推送事件。
您还需要编写并安装一个侦听器,它将侦听由 web/service 挂钩作为 JSON 有效负载发送的推送事件(请参阅 GitHub one, or the Visual Studio one)。
Visual Studio integrates with external services as well,它们有自己的侦听器。
从一个远程仓库接收到推送事件后,您可以从中拉取,然后推送到另一个。但请注意,在从一个仓库推送到另一个仓库时,同一分支上的任何并发开发都可能导致冲突。当在每个 repo 上使用不同的分支时,这种方法有效。
也可以通过创建构建定义从 GitHub 中提取更改,然后将更改推送到 VSTS Git 来实现。以下是供您参考的步骤:
- Deploy your own build agent 然后生成 SSH 密钥。
- 为你的 VSTS Git Repo 启用 SSH Authentication 这样你就不需要在你的构建定义中输入用户名和密码。如果您想使用备用凭据,可以跳过第 1 步和第 2 步。
- 创建构建定义和 select GitHub 作为存储库。
- 在构建定义中启用 "Continuous integration (CI)" 选项,以便在 GitHub 中提交新更改后立即触发构建。
- 在您的构建定义中添加一个 PowerShell 脚本以将 VSTS Git 添加为远程并将更改推送到它。
现在,当您在 GitHub 中提交更改时,您应该会看到构建被触发,然后构建将从 GitHub 中提取更改并将其推送到 VSTS Git。
git remote add vstsg ssh://vstsaccount@vstsaccount.visualstudio.com:22/VSTSProjectName/_git/VSTSGitRepoName 2>&1 | Write-Host
git checkout -b master 2>&1 | Write-Host
git push vstsg master 2>&1 | Write-Host