 On today's Visual Studio Toolbox, we're going to see how easy it is for Visual Studio users to adopt Git and GitHub for all your source control needs. Hi, welcome to Visual Studio Toolbox. I'm your host Robert Green and joining me today are Sachin and Samit. Hey guys. Hey, Robert. Welcome to the show. Thank you. We're going to be talking about source control, which on the face of it seems like a pretty dry topic, but we're going to be talking about using Git and GitHub to do your source control and how well integrated it is into Visual Studio, and how easy it is to do your source control and Git. So it actually winds up being a pretty exciting topic. Absolutely. There's a lot of interest in it. So yeah, Git and GitHub are absolutely exciting stuff to talk about, and today we are going to learn about how easy it is for GitHub users to start using GitHub and safely bring the open source workflows within their companies. So before we begin and teach about how to do that, let's step back and just say why. Why should I move my source code management to Git and GitHub in particular? That's a great question. You always start with why. Why do you have to care about something? Git is a modern version control system that has won the hearts and minds of developers worldwide. It has become the leading choice for many teams, and it's the number one version control system out there in the industry. There are several factors that contributes to the success of Git. It's free, it's open, it's lightweight, and it's distributed. But a top factor for the quick success of Git, I would say is the GitHub. GitHub provides free repositories for open source public projects. We have about 100 million repositories with 33 million developers actively contributing on GitHub. It also provides GitHub Enterprise for organizations that demand security, compliance, and more deployment controls. Cool. Wow. So GitHub Enterprise, are they public repos or are they private repos? They are private repos. When you want to bring that GitHub, the open source development back into your organizations inside the firewall, that's GitHub Enterprise for you. Awesome. Those numbers are impressive. You said 33 million developers, right Sachin? That is correct. And 100 million, so that's on average three, so I'm above average. That's good to know. Yeah. Absolutely. Sachin, how exactly is Git different from say Subversion or TFVC? Yeah. So unlike TFVC, a Subversion is a distributed version control system. So what that means is the changes, the historical data is not stored on a central server, but every developer gets a copy of the repository downloaded onto their machines. So that means you can do all your version controlling within your local repository, you could do that even when you're offline. And when you come back online, when you get connection to the server, you can push all those changes. And it's a lot faster too. That is right. Right. So this is completely different from central version control system where every developer has to be connected to the central server. That's awesome. Yeah. But then if I'm new to Git, will that be a steep learning curve? That's a good question. GitHub provides several options for you, like GitHub desktop and GUI that makes it easy. But having said that, if you are completely new to the distributed version control system model, there could be a learning curve. But thanks to Visual Studio, we make it so easy for our Visual Studio users. We have a GitHub extension that makes it so easy for developers to connect and download and work with GitHub. Yeah. Like most things, there's a command language you can use. You can go into the command window and type Git commands, which is not a bad way to learn it the first couple of times like push, pull, you get to learn what those mean. But pretty quickly, a lot of people may include to get tired of typing and we just want to integrate it into Visual Studio and let Visual Studio do all the work. So it's same thing with Azure portal, right? You can do everything in the portal, not a bad idea to play around with the CLI and the commands, but eventually you might want to just head back into Visual Studio and let it do. Like me, once you get familiar, you like to use CLIs and that's much faster. Also, you don't want to toggle between too many applications and windows. You want to work from one place and for a Visual Studio user, of course, that one place is Visual Studio. Yeah. So you want to show us? Oh, yeah, sure. So let me get to my machine here. So as you can see, I have Visual Studio 2019. Yes. Install on my machine. Brand new Visual Studio 2019. Yep. Just released a few weeks back. So what you see is right on the startup page, we have an option for you to connect and download and work with GitHub. That's because we have this extension that comes with the installer. So you can install it when you install Visual Studio 2019, or if you haven't upgraded to 2019 yet, you are a 2015 or a 2017 user, you can go to the Visual Studio marketplace and download that extension and install it. Right. Once you have it installed, you can connect to GitHub from here. But I'm going to start from the scratch. I'm going to show you how to put a project into GitHub first. So let me open a project that's on my local machine here. So I'm opening up this Parts Unlimited project, and this is not yet on any version of the control system. It's unlimited, man. I'm telling you, it's making a huge comeback. Absolutely. Mickey Gisset was on the last show. He was using Parts Unlimited. You guys are using that. It's a old sample. I'm a big fan of Gene Kim, and I have read this Phoenix project. It's Parts Unlimited Renaissance here on Toolbox. So let me open up my project here, and what I'm going to do is I'm going to, like, place this into a version control system. So here, as you can see, and as you can expect from Visual Studio, you have options. So I'm going to add this, and you will notice from the output window, a new Git repository is created by Visual Studio. So this is a local Git repository. Right. Right. So now a version control is created. Now I can start making changes. I can do the equivalence of checking my code. When I'm ready, I can push this to my GitHub. So the key there is this is now under source control using Git, which is basically the source control plumbing, and then you could just use Git locally. You don't have to use GitHub. You don't have to use the other places that support Git like Azure DevOps and there's others. So again, getting back to one of the benefits of Git is because it's distributed, you can do it all locally, and if you're never going to share the code with anybody else and you're never going to use more than one computer, and you don't want to back up stored somewhere else, then you wouldn't have to put the code someplace like GitHub. But you probably want to. You want to do that. No other reason than to have the backup and then be able to go home and fire up your home machine and be able to work on the code. Absolutely. Also, it's a lot about collaboration. So as we know, a lot of the largest open source projects including Visual Studio code, they have been developed because of the innovation happened because of collaboration of a lot of developers. So at least within an enterprise, in the context of private repos, you do want all your other colleagues to contribute to your code base to innovate. I'm going to show that, we call this the code workflow in GitHub at the full request. Before I go there, let me put this in to my GitHub repository. So here I go to my GitHub tab and as you can see, it says this repository is not yet on GitHub. So I'm going to push this. Let me adjust this window, let me close this. There we go. I'm going to click on get started. If you have not logged in before, it's going to prompt you to login. But since I've logged in, I don't have to do that. I'm going to click on publish your GitHub. So at this point, I just pick the account that I want to use. So you can see I have a few accounts and I have my personal free GitHub public repositories, or I can choose my GitHub enterprise. So I'm going to put this into my enterprise repository and I'm going to publish this. So now my code is published onto GitHub. If you have two-factor authentication set up, you'd get notified. So at this point, I typically have to get my phone out. I use the authenticator app. That's much easier. Right. So there you go. So the repository has been created. Now, a developer, I mean, others can go in and check out the code and start working on it. I can show you that. Let me switch to a different mission here. We should see it 2019 again, but on a different virtual machine. So I can show you like if I'm another developer, I'm a colleague and then I can go and check out the code. Right. So I click on clone at this time. I can specify if I know the URL, or I simply click on browser repository. So it's going to go and fresh that project that we just published. So I'm going to take that and it's going to get downloaded the code. Remember, this is distributed. So all the code gets downloaded here. I specify where I want to download it. I can choose wherever I want. I'm going to just keep the default and I'm going to say clone. So that's it. So it gets cloned onto my local repository and it opens the solution and now I can start making my changes. Right. So Sachin, we hear a lot about pull request and branches. So what are branches and what is a pull request? That's a great question. So a big advantage to me is the code workflow process. So when you make changes, often users create a feature branch and keep those changes isolated in those branches. Right. And when it is time and when you want to notify others that you are ready to merge these changes with the main branch, you create a pull request. So it's a way of notifying others that, hey, I have made some changes, please take a look at my changes. If you like it, then you can pull this into the branch. So it's a little bit like pure review also within the workflow. That is right. So I can choose. It's also a great way of, if you're letting other people contribute, but you still want to maintain control of the code, right? So you can make a pull request on .NET, for example. But that doesn't mean your code's going automatically. The team will review it and then talk to you about it. So that's a request, right? I like to call that as a merge request. So that's why it's not a push request, but it's a pull request. I can decide what changes comes into my branch. To a point, Robert, yes, someone needs to approve before you can go ahead. Right. So let me show you that. So let's assume that I'm going to build in an awesome feature. So I'm going to go to my Visual Studio here and to the Team Explorer, and I'm going to create a branch. I'm going to create a local branch first. So I'm going to click on New Branch, and I'm going to call this My Awesome Feature. So I create this branch, and I'm going to check this out immediately. You can see, if you notice this, and I was showing master, now since I've checked out, it has moved in a change to this particular branch. Now, all the changes that I do here stays in this branch. So let me go and make a change. So let me go to my solution here. I'm going to open up a c-show file, and I'm not going to show my coding skills here. I'm just going to make some changes. I'm going to make, let's say, My Awesome Feature goes here. So I make this change, I save this, and I need to check this in. Right. So I haven't shown you this. So let me show you how you do this check-in. We call this process and I'll come in. So if I go and look at, click my changes, I should see this, and I change this particular file, and if I open this one, I would see what exactly I changed. I'm going to check this in with the message, add a new line, and I'm going to commit and push this. So when I do a commit, it goes to my local repo. When I say commit and push, it's going to do the local repo and then push it to the remote repository as well. So I say commit and push, it goes into the branch. Right. So that's another benefit of it being distributed. You have your own copy, you can commit and work on it until you're ready to let other people see your coding skills. So you might be halfway in between and you haven't figured out, it doesn't work yet, it's failing the tests in your machine, it doesn't do what it's supposed to do. Only when you're ready can you push and share with others. Then you as a team can figure out what the policy is. How long can you keep something checked out before you publish it? That's right. I mean, you can create pull requests at any time, not just when you're ready to merge the changes, but let's say that you need help, you need advice from your colleagues, and how to solve a problem. You could do that. So here, as you can see, it shows that I have some changes in my branch and I can create a pull request. I'm going to go and create a pull request and I'm going to say, I want to merge my changes that I just created in my feature branch here with my master branch. So I can put in a message and I can say create pull request. So now this goes into my team members who can come and look at the changes, they can comment and approve my changes. Probably you did some inner loop testing and now you feel safe now to share and get others involved with reviewing your code. That is right. So if I switch back to the other window and if I go to my GitHub, I should see if I let me refresh here. So I should see the pull request that I just created. This is brand new in 2019, the ability to look at the pull requests and approve them from inside Visual Studio. What I like about this is- 2017 you had to go to GitHub to do it, which is not terribly difficult, but again, it's a context switch. Exactly. You do have to toggle between applications. Right. Not just that. If you are looking at changes that's not code related, it's easier to do it on the web, but if it is code, I like to use Visual Studio. Yes. Because it gives me all, I can use all of the navigational features. I can step into, I can look into a different things, so I can understand the context and then I can approve or reject. It's your command center, if you want. Exactly. All right. So let me open this pull request. I can see this is initiated by my colleague, and I should be able to see the exact changes. So if I bring this up, again, I see the different though where I can see what was before and what's the change. As I said, if you want to comment, you can comment directly on the change here. So I could say, I like this code, I like this change, I can put emojis, I could ask questions like how about updating docs. Right. Or maybe writing some code that actually does something. Oh, yeah. So I have provided my comment, so this comment now goes back to my colleague. If there's any action item, they can fix that first and then when I'm done, I can approve the changes. So at this time, I have said, okay, the changes look good and it can be merged. To do the merge, you have to go out to GitHub. Luckily, I have view on GitHub here, so I'm going to bring this up. So it should upload this on my browser. It takes me to the pull request page and if I scroll bit here, you can see that the approval has been provided and now my changes can be merged into the main branch. Right. I click on this one and emojis done. Fantastic. So this is like to Robert's earlier point. I can have a lot of my colleagues start contributing, but yet there is still control and you still get to approve before code goes into your master branch. Yeah. That increases the quality before you commit your changes. Right. Awesome. So that's wonderful Sachin. Like you showed how we can upload our code, do commits, how to create a new branch, do a pull request, merge the branches, all without living visual studio. Yes. That's right. We also have integration with the Azure Pipelines and Azure Boats that takes it even further. Right now I can take my code and with those integrations, I can set up CI CD pipelines and I can also relate my changes to the backlog items. That's what Mickey was showing in the previous episode. So if people want to see how to do that, they just have to go back one episode. Got it. We kind of did these out of order, I guess. I didn't really think of it that way. We did pipelines and then the week after we did the search control, but that's okay. Got it. I guess we can also track, commits, and pull request and associate them with work items in Azure Boats, which gives full end-to-end traceability. Right. Yeah. For Visual Studio users, I think you have even a better news. I do. Yeah. So I'm happy to announce that we have a new offering Visual Studio with GitHub Enterprise, which is an easy and economical way for Visual Studio users to acquire GitHub Enterprise. So if you are a Visual Studio professional or a Visual Studio Enterprise subscriber, you can upgrade to this new offering and save money. You can find more details at the aka.ms slash vs. with GitHub. Fantastic. All right. So we looked at today a quick overview of how easy it is to be using Git to do source control from inside Visual Studio. We'll put up some resources where people can learn more. The docs are fantastic. I love saying that. The docs are fantastic. We'll have links to that and maybe just some additional resources as you mentioned. It's free. It's easy to use. It's great stuff. Thanks so much for coming on the show. Thank you so much for having us here. Awesome. Thanks a lot, Robert. Hope you guys enjoyed that and we will see you next time on Visual Studio Toolbox.