LinuxCommandLibrary

az-repos

Manage Azure DevOps Git repositories

TLDR

List all repos in a specific project

$ az repos list [[-p|--project]] [project_name]
copy

Add policy on a specific branch of a specific repository to restrict basic merge
$ az repos policy merge-strategy create --repository-id [repository_id_in_repos_list] --branch [branch_name] --blocking --enabled --allow-no-fast-forward false --allow-rebase true --allow-rebase-merge true --allow-squash true
copy

Add build validation on a specific repository, using an existing build pipeline, to be triggered automatically on source update
$ az repos policy build create --repository-id [repository_id] --build-definition-id [build_pipeline_id] --branch main --blocking --enabled --queue-on-source-update-only true --display-name [name] --valid-duration [minutes]
copy

List all active Pull Requests on a specific repository within a specific project
$ az repos pr list [[-p|--project]] [project_name] [[-r|--repository]] [repository_name] --status active
copy

SYNOPSIS

az repos <subcommand> [--organization] [--project] [--output (-o)] [--query (-q)] [--subscription] [--verbose] [--help]

PARAMETERS

branch
    Manage branches in a repository.

create
    Create a new repository in a project.

delete
    Delete a repository.

list
    List repositories in a project.

prune
    Delete empty or unused repositories.

show
    Show details of a specific repository.

update
    Update repository properties like name or default branch.

DESCRIPTION

The az repos command is part of the Azure CLI for managing Git repositories in Azure Repos, a service within Azure DevOps Services or Server. It enables creation, deletion, listing, updating, and inspection of repositories, branches, files, and folders.

Requires the azure-devops extension: az extension add --name azure-devops. Authenticate with az login or a Personal Access Token (PAT) via --token.

Key uses include automating repo lifecycle in CI/CD pipelines, scripting project setups, and integrating with tools like Git. Specify --organization (e.g., https://dev.azure.com/org) and --project for operations. Supports JSON, table outputs via --output. Permissions like 'Contributor' or specific repo scopes needed.

Ideal for DevOps teams handling multiple projects without web UI.

CAVEATS

Requires azure-devops extension and Azure DevOps permissions. Most subcommands need --organization and --project. PAT must have 'Code (read/write)' scope. Not for GitHub or other providers.

INSTALLATION

az extension add --name azure-devops
az extension update --name azure-devops for latest.

AUTHENTICATION

Use az login --tenant <tenant> or --token <pat>. PAT from Azure DevOps user settings.

EXAMPLES

az repos list --organization https://dev.azure.com/myorg --project myproject --output table
az repos create --organization https://dev.azure.com/myorg --project myproject --name myrepo

HISTORY

Added via Azure DevOps CLI extension in 2018, evolved with Azure CLI v2.x updates to match Azure DevOps features like multi-repo support and branch policies.

SEE ALSO

az pipelines(1), az boards(1), git(1), gh repo(1)

Copied to clipboard