- 创建一个Azure DevOps流水线,其中包含CI触发器,将更改从Azure DevOps存储库推送到GitHub上的分支
- 创建第二个流水线,监听来自GitHub的更改并将它们拉回Azure DevOps中的分支
git clone --mirror <source>
cd <repo name>
git remote add --mirror=fetch target <target>
mkdir ../workdir
git fetch origin
git --work-tree=../workdir/ checkout <branch name>
git push target <branch name>
当我测试管道时,出现了这样的错误:
! [rejected] <branch name> -> <branch name> (fetch first)
error: failed to push some refs to 'git@github.com:<target>/<target repo>.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我绝不是 Git 专家,所以非常感谢任何帮助。
更新 #1
下面的截图显示了我构建的管道来将更改推送到 GitHub(基于此 答案),但它仍然无法正常工作。
这是新错误:
Cloning into '<repo>'...
Switched to a new branch '<branch name>'
Branch '<branch name>' set up to track remote branch '<branch name>' from 'origin'.
warning: adding embedded git repository: <repo>
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> <repo>
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached <repo>
hint:
hint: See "git help submodule" for more information.
[<branch name> XXXXXXX] Update from Azure DevOps
1 file changed, 1 insertion(+)
create mode 160000 <repo>
To git@github.com:<org>/<repo>.git
! [rejected] <branch name> -> <branch name> (fetch first)
error: failed to push some refs to 'git@github.com:<org>/<repo>.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
更新 #2
我已更新以下脚本,根据最新答案从GitHub将更改拉到Azure DevOps,但它仍未起作用。
git clone git@github.com:XXX/XXX.git
cd <repo folder>
git config --global user.email "XXX"
git config --global user.name "XXX"
git checkout <source branch>
git add .
git commit -m "Pull from GitHub"
git push https://{AzureDevopsPAT}@dev.azure.com/{org}/{pro}/_git/XXX.git <target branch>
这是错误:
Cloning into '<repo>'...
Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
Already on '<source branch>'
Your branch is up to date with 'origin/<source branch>'.
On branch <source branch>
Your branch is up to date with 'origin/<source branch>'.
nothing to commit, working tree clean
error: src refspec <target branch> does not match any
error: failed to push some refs to '***'
git push
步骤中,您需要在推送 URL 中提供您的 GitHub PAT,就像下面的示例一样:git push https://{yourPAT}@github.com/xxx/yyy.git
。 - Hugh Lingit clone https://github.com/XXX/XXX.git git config --global user.name "XXX" git checkout sourcebranch git add . git commit -m "abc" git push https://{AzureDevopsPAT}@dev.azure.com/{org}/{pro}/_git/delete.git targetbranch
- Steve L.