Repository Configuration

Article: Dec 17, 2024

Repository policies in Azure DevOps allow you to enforce specific standards to maintain consistency, reduce errors, and avoid potential conflicts in individual repositories. These policies or options can be applied to all repositories by default or customized for specific repositories as needed.


Repository Policies and Options

The following table summarizes the policies or options you can set for either all or individual repositories. Policies set for All Repositories set the default for individual repositories added at a later date.

Policy or OptionDescription
Commit author email validationBlocks pushes with a commit author email that doesn't match the specified patterns.
File path validationBlocks pushes that introduce file paths matching the specified patterns.
Case enforcementPrevents case-sensitivity conflicts by blocking pushes that change the casing of file, folder, branch, or tag names.
Reserved namesBlocks pushes that introduce files, folders, or branches with platform-reserved names or incompatible characters.

Microsoft Learn, Set Git repository settings and policies

To configure these settings, follow the steps below. All settings are available in the same location for consistency.

How to Configure

  1. Navigate to Project Settings in your Azure DevOps project.
  2. Select Repos > Repositories.
  3. Choose the repository you want to configure.
  4. Go to Policies and select the specific policy or option you wish to configure.
  5. Adjust the settings as needed to meet your requirements.
  6. Save the changes to apply the updated policy settings.

Commit author email validation

This policy ensures that only commits from approved domains or agents are allowed. Configure the following domains and agents to validate commit authors:

*@example.com; Build Service (organization)

Case enforcement

This policy prevents case-sensitivity conflicts by blocking pushes that change the casing of file, folder, branch, or tag names.

Enable this policy to maintain consistency and avoid errors.

Reserved names

This policy blocks pushes that introduce files, folders, or branches with platform-reserved names or incompatible characters.

Enable this policy to ensure compatibility and prevent naming conflicts.

File path validation

The File Path Validation policy ensures that files are only added to specific folders, preventing accidental pushes to incorrect locations, such as the root directory.

Example, File Path Validation Configuration

/*;!/App/SourceCode/*;!/App/BinaryOnly/*;!/Pipelines/*
  • Use /* to block all file paths by default.
  • Exclude specific folders from the block using !/[path]/*.
  • Separate multiple paths with ;.

Branch Policies and Configurations

Enforce branch protection rules to ensure code quality and maintain repository integrity. Below are the recommended settings in Azure DevOps to enforce these rules effectively:

How to Configure Branch Policies

  1. Navigate to Project Settings in your Azure DevOps project.
  2. Select Repos > Repositories.
  3. Choose the repository you want to configure.
  4. Go to Policies and scroll to the Branch Policies and select branch.
  5. Adjust the settings as needed to enforce branch rules.
  6. Changes take effect immediately.

Branch Policies

To enforce branch protection policies, configure the following settings:

Require a Minimum Number of Reviewers

Ensure code changes are reviewed before merging:

  • Minimum number of reviewers: 1 or 2
  • Allow requestors to approve their own changes
  • When new changes are pushed:
    • Reset all code reviewer votes

Check for Comment Resolution

Require all comments to be resolved before completing a pull request:

  • Required

Limit Merge Types

Control branch history by restricting merge types:

  • Allowed merge types:
    • Basic merge (no fast-forward)
    • Squash merge
    • Rebase and fast-forward
    • Rebase with merge commit

These settings help enforce consistent code quality and maintain a clean and linear commit history.


Allowed Branches Configuration

Restrict changes to specific branches to ensure version control remains organized and development branches are correctly structured.

Over time, this approach keeps the branches clear, manageable, and easier to maintain.

Restrict deployments or changes to specific branches: In repository settings, navigate to the Approvals and Checks tab > Add check > Branch control

  • Configuration:
    • Allowed branches: refs/heads/features/* , refs/heads/releases/*
    • To allow all branches: *