What is version control?

Why use Version Controls? You can:

(Source: What is version control? - Learn | Microsoft Docs)

What is Git?

Git is an open-source version control system and is the most widely used vcs in the tech industry. Git is also a distributed Version Control System. This means that it does not rely on storing all version of a project file, on a centre server. Instead, users create a clone of the repository on their local machine, which includes the full history of the project.

There are several ways we can interact with Git:

gitworkflow.png

(Source: fundamentals of Git)

Let's look at some of the commands mentioned in this overview, in abit more detail:

it is also useful to know the following:

(Learn more about the fundamentals of Git here)

Git workflow

Version control has a general workflow that most developers use when writing code and sharing it with the team. Git has a version of this workflow using terminology and commands unique to Git.

These steps are:

gitworkflow.png

Throughout the rest of this lab tutorial you'll learn about how to use the above commands.

(Source: Azure Repos Git tutorial)

Visual Studio 2019

Signin.png

connecttoproject01.png

connecttoproject02.png

When a project is created in Azure DevOps, there is a default repository. In some cases, you may find needs for a new repository, you can simply do so via the web portal.

Create a repo using the web portal

Navigate to the Repos page in your project.

newrepository

From the repo drop-down, select New repository.

newrepository

In the Create a new repository dialog, verify that Git is the repo type and enter a name for your new repo. You can also add a README and create a .gitignore for the type of code you plan to manage in the repo. A README contains information about the code in your repo. The .gitignore file tells Git which types of files to ignore, such as temporary build files from your development environment.

Set options for your new repo in the Create a Git repo dialog. When you're happy with the repo name and choices, select Create.

newrepository

You will now have a new repository in your project.

newrepository

You can follow the previous step to clone this new repository to your local and start using it.

newrepository

On the menu, click Git and go to Manage Branches

branch

Choose the parent branch (usually main or master) to base your changes, right click and choose New Local Branch From....

branch

Supply a branch name in the required field and select Create Branch.

branch

Visual Studio automatically performs a checkout to the newly created branch.

branch

Once you have completed changes or added new files in your branch, in this case, I have created two new files "NewFile 1.txt" and "NewFile 2.txt", I would like to commit changes.

Git does not automatically add changed files to the local repository when you create a commit. You must first stage your changes to let Git know which updates you want to add to the next commit. Staging lets you to selectively add files to a commit while excluding changes made in other files.

Stage changes

Create a commit

When you commit in Visual Studio you can push the commit to a remote repository.

push

After you have pushed your first commit, the sync button sync becomes available, it carries out two actions, Pull and Push.

This helps keep your local branch up to date with the remote branch.

Create a new PR from the Azure DevOps project website

You can create PRs for any branch from your project's Pull requests page on the web.

You can access PRs for any branch from your project's Pull requests page on the web.

push

Once all required reviewers approve your pull request (PR) and the PR meets all branch policy requirements, you have two options:

push

To merge your changes into the target branch, click Complete

push

Choose Squash commit as the Merge Type and click Complete merge

push

Your changes have now been merged into the target branch

push