Clone All Azure DevOps Repositories in a Project
This is a quick post to show how to clone all repositories in an Azure DevOps project. This is useful if you need to clone all repositories to your local machine and there are a lot of them or to run a script against all repositories. This script requires the Azure CLI and the Azure DevOps extension.
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$PAT,
[Parameter(Mandatory=$true)][string]$Organization,
[Parameter(Mandatory=$true)][string]$Project
)
$env:AZURE_DEVOPS_EXT_PAT = $PAT
az devops configure --defaults organization=https://dev.azure.com/$Organization/ project=$Project
az repos list --query "[].{name:name, cloneUrl:webUrl}" --output json | ConvertFrom-Json | ForEach-Object {
git clone $_.cloneUrl
}
This script sets the Azure DevOps Personal Access Token (PAT) in an environment variable, configures the default organization and project, lists all repositories in the project, and then clones each repository.
Snippet from Jay Vilalta - 2025-02-27