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
- Project Settings → Repos → Repositories
- Click on "New repository"
- 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
| Policy | Description |
|---|---|
| Require reviewers | Minimum number of reviewers |
| Check for linked work items | Link to a work item |
| Check for comment resolution | Resolve all comments |
| Limit merge types | Squash, rebase only, etc. |
| Build validation | Pipeline must pass |
| Status checks | External 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 - Code Search
6.1 Search syntax
| Syntax | Description |
|---|---|
function:login | Search for a function |
class:UserService | Search for a class |
file:*.ts | Filter by file type |
path:src/ | Filter by path |
repo:mon-app | Search 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
- Fork the repository
- Clone your fork
- Create a branch
- Make your changes
- Push to your fork
- 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.