You are on page 1of 49

Version Controlling with

Git in Azure Repos

1
Contents
1 Introduction ........................................................................................................................................................... 3
2 Lab Scenario ........................................................................................................................................................... 4
3 Documentation Links .......................................................................................................................................... 5
4 Pre-Requisites ....................................................................................................................................................... 6
4.1 Set up an Azure DevOps organization ................................................................................................................... 6
4.2 Applications required for this Lab ......................................................................................................................... 6
4.3 Creating Parts Unlimited Team Project ................................................................................................................ 7
4.4 Install and Configure Git and Visual Studio Code ............................................................................................ 11
5 Cloning an Existing Repository ..................................................................................................................... 27
6 Manage branches from Azure DevOps ........................................................................................................ 33
6.1 Creating a new branch ............................................................................................................................................. 33
6.2 Delete and restore a branch................................................................................................................................... 39
6.3 Locking and Unlocking a branch .......................................................................................................................... 41
6.4 Tagging a Release ...................................................................................................................................................... 43
7 Managing Repositories .................................................................................................................................... 45
7.1 Creating a new repo from Azure DevOps ........................................................................................................... 45
7.2 Deleting and Renaming Git Repos ........................................................................................................................ 47
8 Summary .............................................................................................................................................................. 49

2
1 INTRODUCTION

➢ Team Foundation Version Control (TFVC): TFVC is a centralized version control system.
Typically, team members have only one version of each file on their dev machines. Historical
data is maintained only on the server. Branches are path-based and created on the server.

➢ Git: Git is a distributed version control system. Git repositories can live locally (such as on a
developer’s machine). Each developer has a copy of the source repository on their dev
machine. Developers can commit each set of changes on their dev machine and perform
version control operations such as history and compare without a network connection.

3
2 LAB SCENARIO
Azure DevOps supports two types of version control, Git and Team Foundation Version
Control (TFVC).

Git is the default version control provider for new projects. You should use Git for version
control in your projects unless you have a specific need for centralized version control
features in TFVC.

This activity guide cover steps to:


➢ Configure the Lab prerequisites
➢ Work with branches in Azure Repos
➢ Work with repositories in Azure Repos

4
3 DOCUMENTATION LINKS

1. Version Control.

https://docs.microsoft.com/en-us/devops/develop/git/what-is-version-control

2. What is Git?

https://git-scm.com/docs

3. VS Code

https://code.visualstudio.com/docs

4. MicrosoftLearning/AZ400-DesigningandImplementingMicrosoftDevOpsSolutions

https://github.com/MicrosoftLearning/AZ400-
DesigningandImplementingMicrosoftDevOpsSolutions

5
4 PRE-REQUISITES

4.1 Set up an Azure DevOps


organization
1. You need to have a Active Azure Account (Paid or Free).

Note: If you don’t have Azure Account please check the Activity Guide on “Create Azure
Account & Access Console” under Bonus Module.

2. You need to have a Active Azure DevOps Account.

Note: If you don’t have Azure DevOps Account please Check the Creating FREE Microsoft
Azure DevOps Account” under Module-1.

3. You need to Create PartsUnlimited Team Project from Azure DevOps Generator with
having PartsUnlimited as Template.

4.2 Applications required for this


Lab
4. You also need to have Git 2.29.2 or later installed on your local system.
5. You need to have Visual Studio Code installed on your local system with C# extension
installed in it.

6
4.3 Creating Parts Unlimited Team
Project
In this task, you will use Azure DevOps Demo Generator to generate a new project based on
the Parts Unlimited template.

1. Click on this link to automate the process to create a Parts Unlimited Project

https://azuredevopsdemogenerator.azurewebsites.net/

7
2. Next Click on Sign in and use the account that you have used to create Azure DevOps
Subscription.

3. Select your Azure DevOps organization and enter the project name “Parts Unlimited”.

Click Choose Template.

8
4. Select the PartsUnlimited template and click Select Template.

5. Click Create Project and wait for the process to complete.

9
10
4.4 Install and Configure Git and
Visual Studio Code
In this task, you will install and configure Git and Visual Studio Code, including configuring the
Git credential helper to securely store the Git credentials used to communicate with Azure
DevOps. If you have already implemented these prerequisites, you can proceed directly to the
next task.
1. Open Visual Studio Code.

11
2. From the main menu, select Extensions and Type C# and select the first option.

3. Click on Install on the C# Extension Page

12
4. Now you can see that the C# Extension is installed.

5. Open your browser and click on the link to download Git


https://git-scm.com/download/win

13
6. Run the installer then click on Next.

14
7. Keep default and click on Next.

15
8. Let the default applied and click on Next.

16
9. Keep default setting and click on Next.

17
10. Select a text editor like atom, sublime text. I have selected Vim text as it is very light weight
and then click on Next.

18
11. Make sure Let Git decide is selected then click on Next

12. Keep default and click on next

19
13. Keep default and click on next.

14. Click on Next.

20
15. Use Default setting and click on Next.

21
16. Click on Next.

22
17. Let the default configuration selected and click on Next

18. Click on Next

23
19. Keep default and click on Install

20. Click on Finish.

24
21 Click on Terminal > Select New Terminal

22. On the Terminal execute the following command below to configure a credential helper.

git config --global credential.helper wincred

25
23. The commands below will configure your user name and email for Git commits.

Note: Replace the parameters with your preferred user name and email and execute them.

git config --global user.name "Rohit"

git config --global user.email “rohit@example.com”

26
5 CLONING AN EXISTING REPOSITORY
In this exercise, you use Visual Studio Code to clone the Git repository you provisioned as
part of the previous exercise.

1. Open your Azure DevOps account and Select the previously created Parts Unlimited
Project.

27
2. In the Parts Unlimited Project go to the Repos hub.

3. In Repos, Click on Clone

28
4. Click the Copy to clipboard button next to the repo clone URL.

Note: You can plug this URL into any Git-compatible tool to get a copy of the codebase.

29
5. Open Visual Studio Code(VS Code) and press Ctrl+Shift+P to show the Command
Palette.

Note: The Command Palette provides an easy and convenient way to access a wide variety
of tasks, including those provided by 3rd party extensions.

6. Type Git in the Command Palette and press enter to execute the Git: Clone command.

7. Enter the copied Repo URL in the Command Palette and press Enter.

30
8. Select a local path to clone the repo to. Once selected click on Select Repository Location
and wait for a Login prompt to pop-up.

31
9. When prompted, log in to your Azure DevOps Account and wait for your repository to be
copied completely.

10. Once the cloning has completed, click Open to open the cloned repository.

Note: You can ignore any warnings raised about opening the projects. The solution may not be
in a buildable state, but that’s okay since we’re going to focus on working with Git and building
the project itself is not necessary.

32
6 MANAGE BRANCHES FROM AZURE DEVOPS

In this exercise, you will work with branches by using Azure DevOps. You can manage your
repo branches directly from the Azure DevOps portal, in addition to the functionality available
in Visual Studio Code.

6.1 Creating a new branch

In this task, you will create a branch by using the Azure DevOps portal and use fetch it by
using Visual Studio Code.

1. In the PartsUnlimited project Azure Repos, navigate to the Commits pane of the project and
select Branches.

33
2. On the Branches pane, click New branch.

34
3. In the Create a branch panel, in the Name textbox, type release, ensure that master
appears in the Based on dropdown list, in the Work items to link drop-down list, select one
or more available work items, and click Create.

35
4. Switch to the Visual Studio Code window.Press Ctrl+Shift+P to open the Command
Palette.

5. At the Command Palette prompt, start typing Git: Fetch and select Git: Fetch when it
becomes visible. This command will update the origin branches in the local snapshot.

6. In the lower left corner of the Visual Studio Code window, click the master entry again.

36
7. In the list of branches, select origin/release. This will create a new local branch called
release and check it out.

37
38
6.2 Delete and restore a branch

In this task, you will use the Azure DevOps portal to delete and restore the branch you
created in the previous task.
1. Return to Azure DevOps and click the Delete branch from the more actions drop down to
delete it.

39
2. You can Restore branch if you want by searching for an exact branch name. Select Restore
branch as shown below.

40
6.3 Locking and Unlocking a branch

In this task, you will use the Azure DevOps portal to lock and unlock the master branch.
Locking is ideal for preventing new changes that might conflict with an important merge or to
place a branch into a read-only state. Alternatively, you can use branch policies and pull
requests instead of locking if you just want to ensure that changes in a branch are reviewed
before they are merged.

Locking does not prevent cloning of a repo or fetching updates made in the branch into your
local repo.

1. From the master context menu, select Lock.

41
2. The branch is now locked.

3. Now Unlock the branch using the same process.

42
6.4 Tagging a Release

In this task, you will use the Azure DevOps portal to tag a release in the Azure DevOps Repos.
1. Go to your Azure DevOps account and Click on Repos then click on Tags.

2. Click New Tag.

43
3. Enter a name “v1.1” and a Description of “Great release!”. Click Create.

4. You have now tagged the project at this release. You could tag commits for a variety of
reasons and Azure DevOps offers the flexibility to edit and delete them, as well as manage
their permissions.

44
7 MANAGING REPOSITORIES
In this excersice, you will use the Azure DevOps portal to create a Git repository in Azure
DevOps Repos. You can create Git repos in team projects to manage your project’s source
code. Each Git repo has its own set of permissions and branches to isolate itself from other
work in your project.

7.1 Creating a new repo from Azure DevOps


1. From the project Add dropdown, select New repository.

45
2. In the Create a repository pane, in the Repository type, leave the default Git entry, in the
Repository name text box, type New Repo, leave other settings with their default values,
and click Create.
Note: You have the option to create a file named README.md. This would be the default
markdown file that is rendered when someone navigates to the repo root with a web browser.
Additionally, you can preconfigure the repo with a .gitignore file. This file specifies which files,
based on naming pattern and/or path, to ignore from source control. There are multiple
templates available that include the common patterns and paths to ignore based on the project
type you are creating.
Note: We are not creating the Readme and gitignore file.

3. That’s it. Your repo is ready. You can now clone it with Visual Studio or your tools of choice.

46
7.2 Deleting and Renaming Git Repos

In this task, you will use the Azure DevOps portal to delete a Git repository in Azure DevOps
Repos.

Sometimes you’ll have a need to rename or delete a repo, which is just as easy.

1. Open Project settings.

47
2. Select Repositories under Repos.

3. From the New Repo context menu, select Delete repository. You can also rename it here.

48
8 SUMMARY

In this lab, you used the Azure DevOps portal to manage branches and repositories.

49

You might also like