Git API Documentation

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:

  • Creating new repositories
  • Updating repository settings
  • Querying repository information
  • Managing repository permissions
  • Creating and deleting branches
  • Managing tags and other references
  • Setting branch policies
  • Retrieving branch statistics
  • Creating new pull requests
  • Reviewing and commenting on code
  • Approving and completing pull requests
  • Managing pull request policies
  • Retrieving commit history
  • Analyzing commit details
  • Creating and pushing commits
  • Managing commit comments
  • Retrieving file contents
  • Analyzing and modifying code
  • Managing file history
  • Handling binary files

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:

  • An Azure DevOps account with appropriate permissions
  • A Personal Access Token (PAT) or other authentication method
  • The Azure DevOps Node.js API client library

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:

  • Linking pull requests to work items
  • Creating branches based on work item information
  • Updating work item status based on pull request status

See Work Item + Git Integration for detailed examples.

Git repositories and branches can trigger builds and deployments.

Common integration patterns include:

  • Triggering builds on commit or pull request
  • Building specific branches
  • Reporting build status on pull requests

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.