Git is fully integrated into Visual Studio and Visual Studio Team Services. This tutorial looks at how to create a new project and add it to Git source control.
- [Voiceover] In this chapter, I'll look at how to use the Visual Studio tools to work with Git repositories. If you've tried to use Git in the past, you know that the first step is to install Git on your developer computer. The good news is that you don't have to do that because Visual Studio 2015 is fully integrated with Git, and it's already installed. In this video, I'll look at creating a new project, and adding it to a Git repository at the same time we create the new project. Let's look at a few items before I get to that step, though. Let's start by looking in Team Explorer. Click on the Manage Connections button, and then, you'll see that there's several places I can connect.
I can go to GitHub. I can go to my Visual Studio Team Services, Repositories, or I can use something called the Local Git Repository. Let's review what we know about Git. Git uses a distributed system, which means that each developer gets a copy of the repository, so I have a private copy here, and that's known as a Local Git Repository. If I click on the Add button, you'll see that the default location for all Repos is in this place. It's under Users in my personal folder, under Source and then Repos.
This is the suggested location. I can change it in the configuration file. The key thing to remember is Git really doesn't care where the project is. It'll still work with it, even if I've got projects in multiple locations. I'll copy this, and I'll use it later, then I'll go and create my new project. File-New-Project. We're creating a Console application, so I'll go to Windows, and then Classic Desktop. So, here's where I pick where to put the project. This is the normal default, Visual Studio Project, and as I just said a minute ago, Git will work in that location.
I can put it there if I want to, or I could save it out to my Desktop, Browse out here, open my Desktop and put it in my Exercise Files folder. It'll work there, too. I'll be putting it in this Repo location, and you'll notice that down on the bottom, I can create a directory for the solution, and I can also Add to Source Control. It doesn't say anything about the Git, so what's happening here? Let's cancel out of this, and go look in the Tools menu. Look at the Plug-In Selection. Well, here's what's happening. I'm currently telling Visual Studio I want to work with Visual Studio Team Foundation Server, so it's defaulting to settings for that.
We need to switch this over to Git, then click on OK, then go back to that file dialogue. I'll call it Simple Console, and then, what I want you to see now is over here it says Create new Git repository. I'll check that checkbox, and then click on OK. And that's it. I have now created a new project, and it's under Source Control, and it's in a Git repository. You can see the normal padlocks that you saw inside our Visual Studio Team Services project, when I was using Team Foundation Version Control. It's the same thing here, I can right click on this, and choose some source control items here.
Now, it has different items here based on the fact that this is Git. How about just if I go in here and I add a new line, I'll get a red check mark, and now, I've got some menu choices here to Commit that, and remember, I don't need an internet connection. I don't need anything. I can Commit this. The first time you commit a file, and Git is asking you what your name and email address is, and, it doesn't have to be a real email address. It's basically a unique identifier, and I'll just go ahead and just keep it at these items here, and save that, enter my commit message, My first commit, and then, I'm getting a notice here that says, "Backup and share your changes, "Choose a Git service and publish "to public or private repos".
I'll get to that later in this chapter. Right now, we're just gonna work for the first couple videos in this chapter with the local repositories with no second copy anywhere. Just one on my developer machine. In the next movie, I'll look at how to take an existing project and add it to a Git repository.
- Source control principles
- Signing up for Team Services
- Creating team projects
- Adding projects to source control
- Checking in and checking out changes from the repository
- Adding users to a team project
- Tracking work items
- Adding projects to Git
- Using history to understand team commits
- Using tags to label versions
Skill Level Beginner
Q: This course was updated on 08/23/2017. What changed?
A: A new video was added that provides notes for Visual Studio 2017 developers.