Skip to main content

Description

dvc.api.all_branches() returns a list of all Git branches in a DVC repository. This is useful for iterating over branches to compare data, metrics, or parameters across different branches.

Signature

def all_branches(repo: Optional[str] = None) -> list[str]

Parameters

repo
str
default:"None"
Location of the DVC repository. Defaults to the current project (found by walking up from the current working directory tree).Can be:
  • Local file system path
  • URL (HTTP/HTTPS)
  • Git SSH URL (e.g., user@server:project.git)

Returns

branches
list[str]
List of Git branch names in the repository

Examples

List branches in current repository

import dvc.api

branches = dvc.api.all_branches()
print(f"Found {len(branches)} branches: {branches}")

List branches in remote repository

import dvc.api

branches = dvc.api.all_branches(
    repo="https://github.com/example/dvc-project"
)

for branch in branches:
    print(f"Branch: {branch}")

Compare metrics across branches

import dvc.api

repo_url = "https://github.com/example/ml-project"
branches = dvc.api.all_branches(repo=repo_url)

for branch in branches:
    metrics = dvc.api.metrics_show(repo=repo_url, rev=branch)
    print(f"{branch}: {metrics}")

Iterate over all branches and revisions

import dvc.api

# Get all branches
branches = dvc.api.all_branches()

# Process each branch
for branch in branches:
    print(f"\nProcessing branch: {branch}")
    
    # Get parameters for this branch
    params = dvc.api.params_show(rev=branch)
    print(f"  Parameters: {params}")
    
    # Get metrics for this branch
    metrics = dvc.api.metrics_show(rev=branch)
    print(f"  Metrics: {metrics}")

Use cases

Branch comparison

Compare metrics or parameters across different branches

CI/CD workflows

Automate testing or deployment across all active branches

Branch analysis

Analyze experiment results from different development branches

Data validation

Verify data consistency across branches

Build docs developers (and LLMs) love