简体   繁体   English

git 在两个远程仓库之间推送

[英]git push between two remote repositories

What specific syntax needs to be used in order for a computer at an arbitrary location on the internet (location A) to trigger a git push from a public GitHub repository github.com/someuser/source-repo (location B) to a private Azure Git Repo NameOfAzdoOrganization@dev.azure.com/NameOfAzdoOrganization/NameOfAzdoProject/_git/NameOfAzdoProject (location C)? What specific syntax needs to be used in order for a computer at an arbitrary location on the internet (location A) to trigger a git push from a public GitHub repository github.com/someuser/source-repo (location B) to a private Azure Git Repo NameOfAzdoOrganization@dev.azure.com/NameOfAzdoOrganization/NameOfAzdoProject/_git/NameOfAzdoProject (位置 C)?

The empty remote Azure Git Repo (location C) gives the following code to push from a local repo at location A to populate remote location C:空的远程 Azure Git 存储库(位置 C)提供以下代码以从位置 A 的本地存储库推送以填充远程位置 C:

git remote add origin https://NameOfAzdoOrganization@dev.azure.com/NameOfAzdoOrganization/NameOfAzdoProject/_git/NameOfAzdoProject
git push -u origin --all

But what command needs to be run on location A in order to push from location B to location C?但是需要在位置 A 上运行什么命令才能从位置 B 推送到位置 C?

The computer on location A has to clone the repo from location b位置 A 上的计算机必须从位置 b 克隆 repo

git clone github.com/someuser/source-repo.git

then add the repo in location C as remote然后将位置 C 中的仓库添加为远程

git remote add locationC https://NameOfAzdoOrganization@dev.azure.com/NameOfAzdoOrganization/NameOfAzdoProject/_git/NameOfAzdoProject

then push to location C然后推到位置 C

git push -u locationC

You can add --all to that last command if you wish to push all branches instead of jsut the default branch.如果您希望推送所有分支而不是默认分支,则可以将--all添加到最后一个命令。

Unless the repo in location B has a mirroring functionality (like, gitlab let's you mirror any pushes done to a repo to another remote repo), I believe you have to jump through this hoop.除非位置 B 中的存储库具有镜像功能(例如,gitlab 让您将对存储库所做的任何推送镜像到另一个远程存储库),否则我相信您必须跳过这个环节。

I was imagining something like az azdo pull fromLocationB toLocationB.我在想像 az azdo pull fromLocationB toLocationB 之类的东西。

As far as I know, the sandy method is effective.据我所知,沙地方法是有效的。

From you requirement, Location C in Azure Repo is empty.根据您的要求,Azure Repo 中的位置 C 为空。 And you want to move the repo from github to Azure Repo.并且您想将存储库从 github 移动到 Azure 存储库。

You may try to use the az repos import command in Location A.您可以尝试在位置 A 中使用az repos import 命令

az login 

az repos import create --git-source-url https://github.com/xxx/xxx.git --repository {Location C Repo name} --organization https://dev.azure.com/{Org name} --project {Project name}

Note: the repo in Location C needs to be empty.注意:位置 C 中的 repo 需要为空。 It doesn't support importing repo that already has content.它不支持导入已经有内容的 repo。

This method is to import the repo in Github directly to Azure Repo.该方法是将Github中的repo直接导入Azure Repo。 It has limitations.它有局限性。

Hope this can give you a little help.希望这能给你一点帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM