From the course: Visual Studio 2019 Essential Training

Git and GitHub overview - Visual Studio Tutorial

From the course: Visual Studio 2019 Essential Training

Start my 1-month free trial

Git and GitHub overview

- [Instructor] Here we have a small team of programmers working on a project. They are using Git source control. Terry, on the left, is ready to create a new project. So she opens Visual Studio and adds a project. Once she's ready to create a repository, she runs the Git init command. This creates an empty repo on her local computer. Next, she stages any project changes, like adding or renaming files. When done, she commits the changes to the repository. I'll call this the V1 version. As she continues to work on the project, she'll commit her pending changes. Now she's at V2 version. Tadd is back from his vacation, and is ready to start working on the project. Their company uses GitHub as a remote host. That gives each team an easy way to share the repo with their teammates. There are other ways to share files, and other services that provide the remote hosting. This example uses GitHub because that's what LinkedIn Learning uses. Terry connects to GitHub and pushes her local repo to the GitHub site. Now there are two identical copies of the repo. When Tadd is ready, he clones a copy of the GitHub repo onto his developer computer. At this point, there are three copies of the repo available. Tadd could have used another action called fork to copy the repo, but for this scenario we'll ignore that option. At some point, Tadd makes changes and commits his changes to his local repo. He has version three, while the other two repos are still at version two. When Tadd is ready, he pushes the updates to GitHub. Now Terry is one version behind the other repos. Terry needs to sync with the remote repo at some point. When she's ready, she'll pull the changes to her computer. There is a possibility that Terry and Tadd could get out of sync, where both commit to local without pulling the latest changes. When this happens, one of them would need to do a merge and determine the best way to combine separate changes to the common code base. All these actions, like init, add and commit, push, pull, and merge, are available from the Git command line or from the Visual Studio tools. That's a basic overview of the actions available for Git and remote repositories. There are many more actions available. Here is a partial list of interesting actions. Now let's look at how this works for us and how I use GitHub for this course. This is a simplification, but useful for understanding how you can access the example code for the rest of the course. I created a repository on my local computer and pushed the repo to GitHub. You can clone the repo to your computer to get the example code. Keep watching this chapter to learn more details. But first, we need to look at the concept of Git branches. Nearly every source control system has some form of branching support. You can think of a branch as a separate line of development. We could use a branch to build out a new feature. We could make a branch to try out a new idea. Developers can work on a branch in isolation. Their commits go into the branch, not the main trunk, for the project. Changes to the branch won't affect the main code base, and they won't affect the other branches either. One of the best parts of Git branches is the ability to instantly switch to other branches. This means I can stop working on my idea branch and start contributing to a feature branch. Later I can go back to the idea branch for more work, or delete the branch if the idea is not viable. Because of this isolation, branches provide a nice way to distribute code examples for LinkedIn Learning courses. The instructor makes one code repository per course, and many branches within the repository. Each video in a course could have a separate branch. So to follow along with the code, open the branch. To see the completed code at the end of a video, open the finished branch. That's the way this course works. For the first couple of chapters, I used zip files for the examples. Now we'll use GitHub. You'll see how to use GitHub repos and branches in the rest of this chapter.

Contents