Azure Repos Basics
Tags: webdev, programming, cloud, github
Published: 2024-01-30 00:09:44

## How to clone already existed Repository.
- Go to Azure DevOps from your browser and navigate to the project.
- Click on Repo
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmdrov55mlf4pehgluln.png)
- Click clone
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dpzjeqct8ry72hc3cbt.png)
- Copy the clone url under command line by clicking copy to clipboard.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prwb8mytffb0wuziq37s.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ssupj3zych4j2bdaptz0.png)
- Type Git in the search box and select Git: clone
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k06mqwnldruk6shehwmq.png)
- A box displaying provide a repository url will pop up, paste the copied url and press Enter.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cu9zf4ykxuymg64bcaa2.png)
- Choose a local path where your cloned repo will be and click select a repository destination 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8a75i640edzfzk4a1xuz.png)
- You will be prompted to log into your DevOps account. Click open to open the cloned repository
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/emmdveh435sompi12qu1.png)

## How to commit changes
- After clicking open, the cloned repo will be under Explorer tab.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p01daigwh69mx1pzje7b.png)
- Follow this path from the Explorer tab /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/CartItem.cs and click CartItem.cs to open it
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qk42eytuuvsygg2v7exz.png)
- Add a comment to the file on line 8 and click Ctrl + S to save the comment.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x96js098pj04alz8wly8.png)
- Click Source control, enter a commit message and click Commit.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgcc2xaxc81jhtz0cb69.png)
- Click Always whenever asked to automatically stage your changes and commit them directly.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbd149415p1oc2x2qx3x.png)
- In order to synchronize your changes with the server, click the Synchronize Changes button.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mebq4iyna1r9ag4yr6je.png).

## How to review commit
- To review the new commits on Azure DevOps, Click Repo and select commit
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9hvspff7kvmlg2bu7as.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffxbtnscjxop3nk18fdj.png)
- Click source control and click the + sign in front of CartItem.cs to stage changes.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhfnytjlcm5heug6sybc.png)
- CartItem.cs will be prepared for committing without Category.cs. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4duet8tk68n8x056edwf.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84m4h48fqwdapxydbz8v.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4lfe31p6tn3v65ddsrd.png)
- An easy way to visualize how changes were made and when it is made is done by clicking commit in Azure DevOps.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c785a678hsc16x6d6yff.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f0h33w5l0pll5u60u19c.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qilza9n10rbfpx5b11u1.png)

## How to create a new branch in local repository
- Go back to Visual Studio Code.
- From the bottom left, click master branch.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51ikiy4n0xzelsix3tzu.png)
- Click Create new branch from…
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsy53anqmvl798btt1an.png)
- provide a name for the new branch and press Enter.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh0hbu5zzspxgukq98yy.png)
- Click on master for reference branch.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb2erhf9ciu4iwyf1sav.png)
- The name of the branch at the bottom left will be the new branch.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6ulxqw0arvhp7gw1oz4.png)

## How to work with branches
- Publish the branch by clicking on the button beside the branch.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3946wb215155rfaat47t.png)
- We need to go back to Azure DevOps and click Branches to check the new branch.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21nwpucu3s6qtoqshgcb.png)
- Click on the ellipsis button on the branch and select Delete branch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxvo4oqy2e8ij2fsbd85.png)
- Confirm delete
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3brr7ja7z7ychjk5d54.png)
- Go back to Visual Studio Code and click dev branch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5lrgreqqq8s9mg1qeydo.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irycs5et75q0ae6ptee3.png)
- Open the Command Palette by pressing Ctrl+Shift+P and type Git: Delete in the search box, select Git: Delete Branch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7y9q5y67peyk34y19j3q.png)
- Select the local branch to delete it.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ft9vvmn3dqtpcu0t0l7l.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wnturqq67lfkoqfsrpwq.png)
- Open the Command Palette by pressing Ctrl+Shift+P and type Git: Fetch, select Git: Fetch (Prune)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bvir88nelvguvasbdo4.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2uuyzqknaruyxslmztpg.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jykizc2e6iejcqthr0q.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgwqcz231jnstoc221wl.png)
- Scroll down to enable Check for linked work items and tick Required
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txj07tiyqryi2ef7iui2.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xrn4w7kq29l642y31r5.png)
- Click Edit button
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb0iub6dctat4bvhd7ix.png)
- Insert  // Testing main branch policy on the first line of the contents and click Commit
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmd1lsuw92j6xl2eau5d.png)
- You will see a warning: Pushes to this branch are not permitted...
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6m5r48z6zl2plinpcwxb.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awu7weu043b74i39cxfj.png)
- Provide a title for the work item and click save.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwttnrthhsjjee434yum.png)
- Next is to go back to Repo and select files.
- Follow this path /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/Category.cs to open
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnt6uwawujzae0w32i7b.png)
- Ensure to change the branch to dev branch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96xyp5phlik26o1ljjhq.png)
- Edit the content of the file by clicking the Edit button
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8jvpzozlizbvboy0nxb4.png)
- Insert  // Testing my first PR on the first line and click commit.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ba2eifu2g2u2oi2rdhy7.png)
- Click commit
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fi73igsvdlxgecz14ro4.png)
- You will see a pop up message showing create a pull request. Select create a pull request
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkm2umbuwscqomumhgts.png)
- Leave the settings as default and click Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r55byidila3339da9fgz.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5g3bn518c9y9pd0fvu7.png)
- Click Approve 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yfvugst60wqae7xj0be.png)
- Notice that all the requirements changed to green and click Complete
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0p1hb01zl2uaf0sscj71.png)
- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdrzfmacm19khmtvrymd.png)
 


## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y6m97a85pp5c4inwralp.png)
- Provide a name for the branch and select the the work items to link from the dropdown 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukt1t3uww9kd6gnhylye.png)
- The new branch will be listed in the list.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7n9oli720p2hfllaeksz.png)
- Go back to Visual Studio Code, press Ctrl+Shift+P to open the Command Palette and type and select Git: Fetch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j2yexpwvpzkurms5wg1.png)
- Click on the master branch and select origin/release
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8v3nhuber6o6ehvvfj5u.png)
- Local branch called release will be created
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aslyarpmutfqinkctkxi.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmj23p1315u2fliaec2c.png)
- To restore a deleted branch, for the exact name in the search box, click the ellipsis button and select restore branch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqmsd3hh3v8m6c231pv5.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xa9uafhqzev5th4lpx8c.png)
- A lock sign indicates that the branch is locked.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w946ajwjvpfxrgu0kw8v.png)
- To unlock a branch, click on ellipsis button again and select unlock.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07en4bwipqoruhk2a5o4.png)

## How to Tag a release
- Click on Tag tab under Repo
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9yfubgb23h4knylyu2af.png)
- Click New tag
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/skx4gsz7nd9grhbugzvj.png)
- provide a name and description for the tag. Click create after
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sh4dxdmw0la4f723d95z.png)
- You can delete a tag by clicking on the ellipsis button in front of it and selecting delete tag
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jypyzsz9pjvxrlrcscwk.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rxw2ze5mthehx30ptdn.png)
- Provide a name for the repository and click create.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv3tfx1qnn6y4zz8z8qb.png)
- The repository is now ready to be cloned.

## How to delete and rename a Git repos
- Click project settings to open it
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1bbno05fwo5tngx6i0nv.png)
- Click repositories under Repos tab, click the ellipsis button in front of the repo to delete/rename and select delete/rename.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ow8cnoo7hnd72aljz3f.png)
- Enter the correct name of the repo and click Delete
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fegpbem7urw1xxlivlqb.png)