Azure Repos Basics

olalekan_oladiran_d74b7a6

Olalekan Oladiran

Posted on January 30, 2024

Azure Repos Basics

How to clone already existed Repository.

  • Go to Azure DevOps from your browser and navigate to the project.
  • Click on Repo Image description
  • Click clone Image description
  • Copy the clone url under command line by clicking copy to clipboard. Image description
  • Open Visual Studio Code. Note that Visual Studio Code must be installed on your computer. Click View tab and select command palette. An straightforward and practical way to access many different tasks, including those offered by third-party extensions, is through the Command Palette. Image description
  • Type Git in the search box and select Git: clone Image description
  • A box displaying provide a repository url will pop up, paste the copied url and press Enter. Image description
  • Choose a local path where your cloned repo will be and click select a repository destination Image description
  • You will be prompted to log into your DevOps account. Click open to open the cloned repository Image description

How to commit changes

  • After clicking open, the cloned repo will be under Explorer tab. Image description
  • Follow this path from the Explorer tab /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/CartItem.cs and click CartItem.cs to open it Image description
  • Add a comment to the file on line 8 and click Ctrl + S to save the comment. Image description
  • Click Source control, enter a commit message and click Commit. Image description
  • Click Always whenever asked to automatically stage your changes and commit them directly. Image description
  • In order to synchronize your changes with the server, click the Synchronize Changes button. Image description.

How to review commit

  • To review the new commits on Azure DevOps, Click Repo and select commit Image description

How to stage changes.

You can add specific files to a commit while preserving the changes made to other files by staging modifications.

  • Go back to Visual Studio Code, open the CartItem.cs file and edit the comment on line 8. Save the new changes with Ctrl + s.
  • Use this path to open another file /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/Category.cs and add comment to line 8. Press Ctrl + S to save the new changes. We now have two files with pending changes. Image description
  • Click source control and click the + sign in front of CartItem.cs to stage changes. Image description
  • CartItem.cs will be prepared for committing without Category.cs. Image description
  • Add a comment to the commit, click the ellipsis button, select commit and click commit staged.
  • Synchronize the committed changes with the server by clicking the synchronize changes button. Image description

How to compare files

  • From the source control, click Category.cs. Two files are placed side by side for easy comparison and to locate where changes was made. Image description
  • An easy way to visualize how changes were made and when it is made is done by clicking commit in Azure DevOps. Image description
  • Clicking the ellipsis button on each commit and and selecting Browse files will offer the ability to move around the state of the commit source. One can review and download the files Image description

Image description

How to create a new branch in local repository

  • Go back to Visual Studio Code.
  • From the bottom left, click master branch. Image description
  • Click Create new branch from… Image description
  • provide a name for the new branch and press Enter. Image description
  • Click on master for reference branch. Image description
  • The name of the branch at the bottom left will be the new branch. Image description

How to work with branches

  • Publish the branch by clicking on the button beside the branch. Image description
  • We need to go back to Azure DevOps and click Branches to check the new branch. Image description
  • Click on the ellipsis button on the branch and select Delete branch Image description
  • Confirm delete Image description
  • Go back to Visual Studio Code and click dev branch Image description
  • Note that the branch deleted in the Azure DevOps is the server branch (the one we published) not the local branch. The origin/dev has not been pruned
  • Change the branch to master by selecting master after clicking dev branch Image description
  • Open the Command Palette by pressing Ctrl+Shift+P and type Git: Delete in the search box, select Git: Delete Branch Image description
  • Select the local branch to delete it. Image description
  • To check if the local branch has been deleted, click master branch on the bottom left and you will notice that the local dev branch is no longer listed. Notice that the remote origin/dev is still showing. Image description
  • Open the Command Palette by pressing Ctrl+Shift+P and type Git: Fetch, select Git: Fetch (Prune) Image description
  • Now if we click master branch on the bottom left, origin /dev is no longer in the list, which means that it has been pruned. Image description

How to set up branch policies

To add policies to the main branch and only approve changes through Pull Requests that adhere to the established policies, use the Azure DevOps portal. Before changes on a branch are merged, you want to make sure they are reviewed.

  • Click on branches under Repos tab, click on the ellipsis button in front of main branch and select Branch Policies Image description
  • In the Branch policies pane, let Require minimum number of reviewers be enabled, type 1 in the Minimum number of reviewers box and tick Allow requestors to approve their own changes Image description
  • Scroll down to enable Check for linked work items and tick Required Image description

How to test the branch policy

  • Click Repos and select files.
  • To test the the policy, we need to make changes and commit it on the main branch. Follow this path /eShopOnWeb/src/Web/Program.cs and open Program.cs Image description
  • Click Edit button Image description
  • Insert // Testing main branch policy on the first line of the contents and click Commit Image description
  • You will see a warning: Pushes to this branch are not permitted... Image description

How to work with Pull request

To integrate a change into the protected main branch, you will use the dev branch and the Azure DevOps site to make a pull request. To track outstanding work with code activity, an Azure DevOps work item will be associated with the modifications.

  • Select work items under Boards section, click + New work item and select Product Backlog Item from the dropdown. Image description
  • Provide a title for the work item and click save. Image description
  • Next is to go back to Repo and select files.
  • Follow this path /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/Category.cs to open Image description
  • Ensure to change the branch to dev branch Image description
  • Edit the content of the file by clicking the Edit button Image description
  • Insert // Testing my first PR on the first line and click commit. Image description
  • Click commit Image description
  • You will see a pop up message showing create a pull request. Select create a pull request Image description
  • Leave the settings as default and click Create Image description Image description
  • Click Approve Image description
  • Notice that all the requirements changed to green and click Complete Image description
  • In the Complete Pull Request pane, select Merge (no fast forward) under Merge type from the dropdown, tick Complete associated work item... under Post-completion options and click complete merge. Image description

How to manage branches from Azure DevOps

  • Go back to Azure DevOps, click Repo and select branches of your project. click New branch Image description
  • Provide a name for the branch and select the the work items to link from the dropdown Image description
  • The new branch will be listed in the list. Image description
  • Go back to Visual Studio Code, press Ctrl+Shift+P to open the Command Palette and type and select Git: Fetch Image description
  • Click on the master branch and select origin/release Image description
  • Local branch called release will be created Image description

How to delete a branch from Azure DevOps

  • Go back to the branch in Azure DevOps, click on the ellipsis button in front of it and select Delete branch Image description
  • To restore a deleted branch, for the exact name in the search box, click the ellipsis button and select restore branch Image description

How to Lock a branch

Locking is the best way to stop new modifications that could interfere with a crucial merge or to make a branch read-only. If all you want to do is make sure that changes in a branch are reviewed before they are merged, you can also accomplish this by using pull requests and branch policies in place of locking.

  • Click the ellipsis button in front of master branch and select Lock Image description
  • A lock sign indicates that the branch is locked. Image description
  • To unlock a branch, click on ellipsis button again and select unlock. Image description

How to Tag a release

  • Click on Tag tab under Repo Image description
  • Click New tag Image description
  • provide a name and description for the tag. Click create after Image description
  • You can delete a tag by clicking on the ellipsis button in front of it and selecting delete tag Image description

How to create a new repo from Azure DevOps

  • Click the + sign in front of your project and select New repository from the dropdown Image description
  • Provide a name for the repository and click create. Image description
  • The repository is now ready to be cloned.

How to delete and rename a Git repos

  • Click project settings to open it Image description
  • Click repositories under Repos tab, click the ellipsis button in front of the repo to delete/rename and select delete/rename. Image description
  • Enter the correct name of the repo and click Delete Image description
💖 💪 🙅 🚩
olalekan_oladiran_d74b7a6
Olalekan Oladiran

Posted on January 30, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Azure Repos Basics
webdev Azure Repos Basics

January 30, 2024