将所有分支从一个 Org Repo 复制或同步到具有相同 repo 的另一个 Org

将所有分支从一个 Org Repo 复制或同步到具有相同 repo 的另一个 Org

我已经编写了 powershell 脚本,它将同步或复制 repo 从一个组织到另一个组织,但是目前该脚本仅同步主分支,而不是所有分支。

以下是代码

<#
.SYNOPSIS
    Sync the Repo one from Org to another Org.
 
.DESCRIPTION
    Repo or Detla sync of entire repo from Org to another org 
    using Powershell script.
#>
 
#Clear Console
Clear-Host
 
# Delete the Old Destination Folder
$Path = "$(System.DefaultWorkingDirectory)\$(API_Repo)\"
if (Test-Path $Path -PathType Container) {
    # Get all files in the folder
    $files = Get-ChildItem -Path $Path
    # Loop through each file and delete it
    foreach ($file in $files) {
        Remove-Item $file.FullName -Force
        Write-Output "Deleted: $($file.Name)"
        }
}
 
#Source URL to fetch the Repo
$Sourceurl = "https://$(SourceOrg):$(PAT)@dev.azure.com/$(SourceOrg)/$(URLSourceProject)/_git/$(API_Repo)"
 
#Destination URL to push the Repo
$DestinationURL = "https://$(DestinationOrg):$(PAT)@dev.azure.com/$(DestinationOrg)/$(DestinationProject)/_git/$(API_Repo)"
 
#Set Location for current folder
Set-Location "$(System.DefaultWorkingDirectory)"
Write-Output "***** Cloning the Source URL*****"
git clone $Sourceurl
 
#Set Location to get the latest repo from source
Write-Output "Source Project: $(API_Repo)"
Set-Location "$(System.DefaultWorkingDirectory)\$(API_Repo)\"
Write-Output "*****Git removing remote origin****"
 
#Git Commands to fetch and push the code
git remote rm origin
 
Write-Output "*****Git remote add****"
git remote add --mirror=fetch origin $DestinationURL
 
Write-Output "*****Git fetch origin****"
git fetch $sourceURL
 
Write-Output "*****Git push to Global Repos****"
git push origin --all -f

我修改了git 获取 $sourceURLgit 获取源地址获取 repo 中的所有分支,但是当我运行管道时,我看到这个警告或错误。

致命:拒绝获取在‘/home/vsts/work/1/s/Polydone.Api’签出的分支‘refs/heads/master’

相关内容