Navigation: Home > API Reference > Git API
The Azure DevOps Git API provides a comprehensive set of methods for interacting with Git repositories in Azure DevOps. It enables developers to programmatically manage repositories, branches, commits, pull requests, and more. This documentation provides detailed information about the most commonly used methods in the Git API.
The Git API is designed to facilitate:
The Git API is frequently used for:
Build automation systems that respond to repository events and trigger appropriate workflows.
Create specialized dashboards that display repository metrics, pull request status, and code quality information.
Implement automated code reviews and quality checks that run when code is pushed or pull requests are created.
Ensure branch policies are consistently applied and monitor compliance across repositories.
Generate statistics and insights about repository activity, contributor patterns, and code changes.
Automate pull request creation, branch management, and other Git workflows to improve team efficiency.
Build tools that help developers search, navigate, and understand code across repositories.
Create utilities for migrating repositories, branches, and history between systems.
This documentation covers:
To use the Git API, you'll need:
To start using the Git API, first establish a connection to your Azure DevOps organization:
import * as azdev from "azure-devops-node-api";
// Connection setup
const orgUrl = "https://dev.azure.com/yourorganization";
const token = "your-personal-access-token";
const authHandler = azdev.getPersonalAccessTokenHandler(token);
const connection = new azdev.WebApi(orgUrl, authHandler);
// Get Git API client
const gitApi = await connection.getGitApi();
// Now you can use the Git API methods
// Example: Get all repositories
const repositories = await gitApi.getRepositories();
console.log(`Found ${repositories.length} repositories`);
The Git API is commonly used in conjunction with other Azure DevOps APIs to create comprehensive solutions:
Git repositories, commits, and pull requests can be linked to work items to provide traceability between code changes and requirements.
Common integration patterns include:
See Work Item + Git Integration for detailed examples.
Git repositories and branches can trigger builds and deployments.
Common integration patterns include:
See Git + Build Integration for detailed examples.
For complex scenarios involving Git, Work Item Tracking, and Build APIs together, see Cross-API Examples.
For a comprehensive view of how Git API methods relate to other APIs, see the API Cross-Reference Table.