Setting Up Azure DevOps Repository: A Step-by-Step Guide

Introduction

This guide will walk you through the complete process of setting up an Azure DevOps repository. Follow these steps carefully to establish your development environment.


Prerequisites

Before you begin, ensure you have:

  • A Microsoft Account

  • Git installed on your local machine

  • Basic familiarity with command-line operations


Step 1: Create Azure DevOps Organization

  1. Open your web browser.

  2. Navigate to Azure DevOps.

  3. Click "Sign in" and use your Microsoft account.

  4. Click "Create new organization".

  5. Fill in the details:

    • Organization name: [your-org-name]

    • Hosting location: [select nearest region]

  6. Complete email verification if prompted.

Note: Choose an organization name that's easy to remember and reflects your team or company.


Step 2: Create Your First Project

  1. In your new organization, click "New Project".

  2. Fill in the project details:

    • Project name: [your-project-name]

    • Description: [optional but recommended]

    • Visibility: Private/Public

    • Version control: Git

    • Work item process: Basic

  3. Click "Create".

Important: Choose Private visibility if your code needs to remain confidential.


Step 3: Generate Personal Access Token (PAT)

  1. Click on the user settings (top right).

  2. Click "Personal access tokens""New Token".

  3. Configure the token:

    • Name: Repository Access

    • Organization: [your organization]

    • Expiration: [set date]

    • Scopes:

      • ✓ Code (read, write, & manage)

      • ✓ Pull Request Threads

      • ✓ Build (read & execute)

      • ✓ Release (read & execute)

  4. Click "Create".

Security Tip: Copy and save the token immediately. Store your PAT in a password manager, never in plain text.


Step 4: Set Up Local Environment

Install Git (if not already installed)

  • Windows:

      # Download Git installer from https://git-scm.com/download/windows
      # Run the installer with default settings
    
  • macOS:

      brew install git
    
  • Linux:

      sudo apt-get update
      sudo apt-get install git
    

Configure Git

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Step 5: Clone Repository

  1. In Azure DevOps, navigate to your project.

  2. Click "Repos""Files".

  3. Click "Clone" (top right).

  4. Copy the HTTPS URL.

  5. Open terminal/command prompt and run:

git clone https://dev.azure.com/{organization}/{project}/_git/{repository-name}
  1. Enter your email when prompted for the username.

  2. Use your PAT when prompted for the password.


Step 6: Make Your First Commit

  1. Navigate to the cloned repository:
cd {repository-name}
  1. Create a README file:
echo "# My First Azure DevOps Project" > README.md
  1. Add, commit, and push your changes:
git add README.md
git commit -m "Initial commit: Add README"
git push origin main

Step 7: Configure Branch Policies

  1. In Azure DevOps, go to Project Settings.

  2. Navigate to RepositoriesBranches.

  3. Click on the main branch.

  4. Set up policies:

    • ✓ Require a minimum number of reviewers (set to 1).

    • ✓ Check for linked work items.

    • ✓ Check for comment resolution.


Troubleshooting

Common Issue 1: Clone Fails

Solution:

# Verify Git credentials
git config --list

# Clear stored credentials if needed
git config --global --unset credential.helper

Common Issue 2: Push Rejected

Solution:

# Pull the latest changes first
git pull origin main

# Then try pushing again
git push origin main

Common Issue 3: Authentication Failed

Solution:

  • Verify that your PAT hasn’t expired.

  • Ensure you’re using your email as the username.

  • Check repository permissions.


Next Steps

After completing this setup, you can:

  • Create your first pipeline.

  • Set up branch protection rules.

  • Configure automated builds.

  • Add team members to your project.


Additional Resources


Reminder: Regularly update your PAT and review security settings.