1

I have written the powershell script which will sync or copy the repo from one org to another org, but currently this script is sync only master branch, but not all the branches.

Below is the Code

<#
.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

I have modified the line from git fetch $sourceURL to git fetch origin to fetch all the branches in repo, but when i run the pipeline i am seeing this warning or error.

fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/home/vsts/work/1/s/Polydone.Api'

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.