Azure DevOps - Cloning and updating all Git repositories
If you have a lot of repositories in your Azure DevOps team, you need an easy way to clone and/or update your local Git repositories.
You first need to install the Az-cli available at: https://docs.microsoft.com/cli/azure/install-azure-cli
Once installed, please run the following in a console:
az extension add --name azure-devops
You also need to login, just once. Run the following in a console:
az login
Create the following files:
Replace C:\YourWorkFolder with the root folder of all your repos.
Replace XXXXXXXXXX with the name of your organisation and project.
For example:
az devops configure --defaults project=TestProject
az devops configure --defaults organization=https://dev.azure.com/TestCompany/
Run the sync.cmd file, and that is it. It will clone new repos if you don't already have them, and will update your repos if you already have some.
You first need to install the Az-cli available at: https://docs.microsoft.com/cli/azure/install-azure-cli
Once installed, please run the following in a console:
az extension add --name azure-devops
You also need to login, just once. Run the following in a console:
az login
Create the following files:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
powershell .\sync.ps1 C:\YourWorkFolder | |
pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([parameter(Mandatory = $true)] [string]$targetDirectory) | |
pushd . | |
cd $targetDirectory | |
# https://docs.microsoft.com/cli/azure/install-azure-cli | |
# az extension add --name azure-devops | |
# az login | |
az devops configure --defaults project=XXXXXXXXXX | |
az devops configure --defaults organization=https://dev.azure.com/XXXXXXXXXX/ | |
$repos = (az repos list | ConvertFrom-Json) | Select remoteUrl,name | |
$repos | ForEach { | |
try | |
{ | |
if (Test-Path $_.name) | |
{ | |
pushd . | |
cd $_.name | |
git pull origin master | |
popd | |
} | |
else | |
{ | |
git clone $_.remoteUrl $_.name | |
} | |
} catch { | |
$ErrorMessage = $_.Exception.Message | |
$FailedItem = $_.Exception.ItemName | |
write-host ("Error detected. Continuing." ) | |
write-host ("$ErrorMessage") | |
write-host ("$FailedItem") | |
} | |
} | |
popd |
Replace C:\YourWorkFolder with the root folder of all your repos.
Replace XXXXXXXXXX with the name of your organisation and project.
For example:
az devops configure --defaults project=TestProject
az devops configure --defaults organization=https://dev.azure.com/TestCompany/
Run the sync.cmd file, and that is it. It will clone new repos if you don't already have them, and will update your repos if you already have some.