Join Reynald Adolphe for an in-depth discussion in this video Git and version control, part of Learning Visual Studio Code.
- [Instructor] Source control is an important part of development. So it's a pretty good thing that Visual Studio Code could integrate nicely with Git. There's a few providers that's available to use; one is, obviously, GitHub; another is Visual Studio Online; yet another is Bitbucket. We're going to be working with GitHub. So the first thing that we're going to want to do is install Git.
So let's go ahead and navigate to Git's website, and we'll go ahead and download for our operating system. My download is complete. I will go ahead and launch this to start the installation process. Now I'll double-click on the Git file. Continue install. Installation was successful. I'll close out of this.
Now I will go to the terminal to check that the installation was successful by typing in git --version. Gives me the version so I know the installation was a success. Now that I'm done verifying that Git is installed correctly, I'm ready to go to my project. So I've gone into the terminal and I've navigated to my MyDotnet directory, which is where my Dotnet project is.
So I will go ahead and launch Code. To start working with Git, what we want to do is to initialize a Git repository. So we click on the Git icon, and then click this button that says Initialize Git Repository. Once that's done, you'll see on the left-hand side here that there are 76 changes, and we are ready to commit that to stage.
So I'll go ahead and put in a comment that says init, and do Command + Enter. Now you'll notice that the number 76 is not there anymore. It's taken into account all the different changes. So why don't we go ahead and actually create a change? So I'm going to create a read-me file; there's already one here, so I'll create another one just called README2 just by clicking the Add File icon.
I'll add a comment that says "Something important". Now you'll notice that on the left-hand side it recognizes that there's been one change, which is that addition of that README file. So by clicking on this Git icon, we can add our comment that says: "Added readme2", and I can click this check to commit all, which is the same, as you could see, as Command + Enter.
All right, so now what I'll do is scoot on over to GitHub, and what I'm going to do is create a repository by selecting New Repository. I will name it MyDotnet. And we don't need to change anything else. We'll leave it public. Since we already have content we're working with, we don't need to initialize this repository.
I'll click Create Repository. Now, as I mentioned, since we're working with an existing repository, that is, we already have content, we can choose this second option, "push an existing repository from the command line", and click this icon here to copy to the clipboard. Having done that, we can scoot on over back to Code. And now let's bring up our terminal by hitting the keys Control + `.
Now I will paste the command that we copied. By pasting this, it already ran the first line. What it will do is connect our local repository with the remote repository. And the second line sets the upstream to be the master branch in the repo. Looks like it's doing its work. And it is done. I'll go back to GitHub to verify that our content is there by simply clicking Refresh.
There you go. There's all our new code on GitHub now. There's the comment that I added, "Added readme". If I click on the README file, actually see the content inside it, it says: "Something important". Why don't I backup here, and actually make a change? So let's come back to Code, choose Explorer, and make sure our README2 is selected.
I'll add another comment that says: "This course is super important". I'll click now on the Git icon, and add my comment. I'll commit it. Now if we click on the three dots here, you'll see we have several options. Sync does a pull, then it pushes.
A push sends the content to the remote. A pull gets the latest from the remote. A sync does a pull and then a push. A rebase is one way to integrate changes. There's actually two ways. The other has to do with merging. But for more information regarding rebasing, you could look at this website here. To start discussing the intricacies of rebasing is beyond the scope of this, but you could definitely read up on it.
So what we're going to do is go ahead and do a simple push. You could see here, there's a little blue dash that starts moving. Now, once that's done, we can come back to GitHub, and take a look at our Dotnet project. Choose the README file, and now it has our latest change. If, for some reason, you get a message that you need to configure the user, what you need to do is just enter in these two commands in your terminal, specifying your username that you have for GitHub and your email that's associated with GitHub.
In this course, learn the basics of Visual Studio Code. Industry expert Reynald Adolphe helps you get started with Visual Studio Code by showing how to use the command line and manage its layout, as well as how to handle multiple instances of the command line. He also demonstrates code refactoring, explains how to prepare for environments like ASP.NET, and shows how to create your first .NET app and Node app. Plus, Reynald covers keyboard shortcuts, and language features.
- Setting up Visual Studio code
- Using the command line
- Preparing for ASP.NET
- Creating your first .NET app
- Creating your first Node app
- Changing themes
- Setting up preferences