Skip to main content

Azure Repos


1 - Overview

Azure Repos provides unlimited private Git repositories to host your source code.


2 - Create a repository

2.1 Via the interface

  1. Project Settings → Repos → Repositories
  2. Click on "New repository"
  3. Name the repo and choose the options

2.2 Via CLI

# Créer un repo
az repos create --name mon-app --org https://dev.azure.com/MonOrg --project MonProjet

# Lister les repos
az repos list --org https://dev.azure.com/MonOrg --project MonProjet

# Cloner
git clone https://dev.azure.com/MonOrg/MonProjet/_git/mon-app

2.3 Import an existing repo

# Importer depuis GitHub
az repos import create \
--git-source-url https://github.com/user/repo.git \
--repository mon-app

3 - Branches

3.1 Branching strategy

3.2 Create a branch

# Via Git
git checkout -b feature/ma-feature
git push -u origin feature/ma-feature

# Via CLI Azure
az repos ref create \
--name refs/heads/feature/ma-feature \
--object-id <commit-id>

3.3 Compare branches

# Via CLI
az repos ref list --filter heads/

4 - Branch Policies

4.1 Policy types

PolicyDescription
Require reviewersMinimum number of reviewers
Check for linked work itemsLink to a work item
Check for comment resolutionResolve all comments
Limit merge typesSquash, rebase only, etc.
Build validationPipeline must pass
Status checksExternal checks

4.2 Configure via CLI

# Exiger 2 reviewers
az repos policy approver-count create \
--repository-id <repo-id> \
--branch main \
--enabled true \
--minimum-approver-count 2 \
--creator-vote-counts false \
--allow-downvotes false \
--reset-on-source-push true

# Exiger un build réussi
az repos policy build create \
--repository-id <repo-id> \
--branch main \
--enabled true \
--build-definition-id <pipeline-id> \
--display-name "Build Validation" \
--valid-duration 720

4.3 Complete configuration

# azure-pipelines.yml pour build validation
trigger: none # Désactiver les triggers automatiques

pr:
branches:
include:
- main
- develop

pool:
vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'

- script: npm ci
displayName: 'Install dependencies'

- script: npm run lint
displayName: 'Lint'

- script: npm test
displayName: 'Tests'

5 - Pull Requests

5.1 Create a PR

# Via CLI
az repos pr create \
--source-branch feature/ma-feature \
--target-branch main \
--title "Add login feature" \
--description "This PR adds..." \
--reviewers [email protected] \
--work-items 123 456

# Lister les PRs
az repos pr list --status active

5.2 Review workflow

5.3 Auto-complete

# Activer auto-complete (merge quand toutes les policies sont OK)
az repos pr update \
--id <pr-id> \
--auto-complete true \
--delete-source-branch true \
--squash true

6.1 Search syntax

SyntaxDescription
function:loginSearch for a function
class:UserServiceSearch for a class
file:*.tsFilter by file type
path:src/Filter by path
repo:mon-appSearch within a repo

6.2 Examples

# Trouver tous les TODO
comment:TODO

# Trouver une définition
def:authenticateUser

# Recherche avancée
class:Controller path:src/api file:*.ts

7 - Git LFS

7.1 Configure LFS

# Installer Git LFS
git lfs install

# Tracker des fichiers
git lfs track "*.psd"
git lfs track "*.zip"
git lfs track "assets/**"

# Vérifier le .gitattributes
cat .gitattributes

7.2 Azure Repos configuration

Azure Repos supports Git LFS natively. No server configuration is required.


8 - Forks

8.1 Create a fork

# Via CLI
az repos fork create \
--repository mon-app \
--organization https://dev.azure.com/MonOrg \
--project MonProjet

8.2 Contribution workflow

  1. Fork the repository
  2. Clone your fork
  3. Create a branch
  4. Make your changes
  5. Push to your fork
  6. Create a PR to the original repo

Summary

In this chapter, we learned:

  • The creation and management of repositories
  • Branches and strategies
  • Branch Policies to protect the code
  • Pull Requests and the review workflow
  • Code Search
  • Git LFS and Forks

Next step

In the next chapter, we will look at Azure Boards for project management.

→ Next chapter: Azure Boards


← Back to the table of contents