Azure Repos Git Tutorial
Table of Contents
Overview
Azure Repos provides Git repositories for source control, offering unlimited, cloud‑hosted private repos. It integrates seamlessly with Azure Pipelines, Boards, and other DevOps services.
Setup & Prerequisites
- Create an Azure DevOps organization or use an existing one.
- Navigate to Repos > Files and click Create a new repository.
- Choose Git as the version control system.
- Install Git on your local machine.
# Verify Git installation
git --version
Clone a Repository
Copy the clone URL from the Azure Repos UI (HTTPS or SSH) and run:
# Using HTTPS
git clone https://dev.azure.com/YourOrg/YourProject/_git/YourRepo
# Using SSH
git clone git@ssh.dev.azure.com:v3/YourOrg/YourProject/YourRepo
Branching & Merging
Create a feature branch locally and push it to Azure Repos:
# Create and switch to a new branch
git checkout -b feature/login
# Make changes, then stage and commit
git add .
git commit -m "Add login feature"
# Push to remote
git push -u origin feature/login
Pull Requests
After pushing a branch, create a pull request (PR) to merge into main
:
- Go to Repos > Pull requests.
- Click New Pull Request.
- Select your source branch and target
main
. - Add reviewers, work items, and a description.
- Click Create and complete the review.
CI/CD Integration
Link your repo to an Azure Pipeline for continuous integration:
# azure-pipelines.yml (basic example)
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseNode@2
inputs:
version: '16.x'
- script: npm install
displayName: 'Install dependencies'
- script: npm run build
displayName: 'Build project'
Best Practices
- Keep
main
stable; use feature branches for work. - Write descriptive commit messages.
- Enable branch policies: require PR reviewers, build validation, and work item linking.
- Use
.gitignore
to exclude binaries and secrets. - Tag releases with semantic versioning (e.g.,
v1.2.0
).