Learn the new Git User experience in Visual Studio 2019

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this is bill raymond microsoft recently modified visual studio 2019 to have a whole new get user experience so i'm creating a new series of videos that walk you through how to use that let's get started everything i'm about to show you in this video works with visual studio 2019 whether it's the free community version which i'm using the professional or the enterprise version what you'll need to do first is go to the start menu and go to visual studio installer and run that application as you can see i have multiple copies of visual studio installed on my computer you're going to need to at least use a 2019 version and you're going to need to use 16.8 or later i'm using 616.88 if you see an update i go ahead and update right now just know that whatever i demonstrate might be slightly changed in the product if you're using a newer version click the modify button then click individual components and search for the word get make sure you select get for windows and github extension for visual studio and install those if they're not already selected when you run visual studio for the first time you'll notice there's a get started dialog here and there's a clone repository option that's actually part of the get and github workflow but we're not going to go there yet right now what we want to do is choose this continue without code option to round out our configuration we need to go to the tools menu and choose options now you might get frustrated at this point when you're watching this video and go oh no he's going to search for the preview features well i am going to do that and choose preview and select preview features but i do want to point out microsoft did officially release the new git user experience they're going to keep iterating on it for some reason it's still listed as a preview feature so just make sure you select new get user experience now there is also this github action support and publish i'm going to turn that on as well but this also has to do with workflows and i'm not going to cover workflows in this video select okay when both are selected and just make sure you have this get menu here at the top of the visual studio environment your menus change frequently in here so if yours don't look exactly like mine that's okay now the next thing we want to do is actually see the user interface forget now i will point out you can actually just use git on a command line on your project whenever you want visual studio works with that just fine but we're going to use the user interface the the ui capability in visual studio so right now we have the solution explorer open up over here your layout might be different but you should have a solution explorer that shows the files in your project right now there's none then there's also the team explorer i've demonstrated the team explorer before and this is sort of the if you will old way of working with git and github you can certainly leave that open and still work with it at some point microsoft might remove this feature go to the view menu and then you'll see git repository i'm sorry get changes and when you do that you'll see a new get changes tab opens up here there's not a whole lot going on right now because we just added the tab and we're not working with the project or git yet the other thing you can do is go to the view menu choose other windows and then choose github and that will open up a new github tab here now if this layout isn't the way you're using it and you want to move things around just do keep in mind you can select a tab hold on to it with your mouse and drag and drop it into the place that you want i like to keep my get changes and github tabs right near the solution explorer because that's where i'm working with my files before we can get started we need to create a project so let's go to the file menu choose new and project i am going to choose an asp.net core web application because that's what i'm comfortable with and if you want to use something else go ahead you can choose any project type and you can put that under get source control so i'll go ahead and click next i'm going to call this the vs 2019 new get experience and click create and i'll choose an empty project which actually isn't fully empty but we'll see that in a second and then click the create button and let that do its thing okay we have a project now and the first thing we're going to do is just run this so i'll just go ahead and choose click the run button up here that says ias express and you can see it's opening up in a browser and we get some text on here that says hello world that's the code that came with this project i'll go ahead and close this and get back into visual studio now as a best practice the minute you create a project before you start coding you should add your code to a source control solution in this case we're using git now we're going to create a local git repository and the word repo or repository is essentially going to be synonymous with a visual studio project or sometimes a solution so just keep in mind it's kind of the folder where all your files exist that's what we're going to call a git repo that's the term that they use now in typical microsoft fashion there's like a lot of ways to put your project into a git repo i'm just going to show you a few of them so first you can go up to the get menu and choose create git repository i'm going to open this and then we'll close in just a moment you can see there's a dialog that says create a git repo and here we can automatically put it up on the github if we want or we could even just make it local and you might even have an existing remote github is nothing but a remote server so there's lots of other products out there that can also be remote servers but i'm going to cancel right now and then i'm going to show you a few other ways you can do this if you come over here to the get changes tab over by the solution explorer where i put it you can see it says create a git repository same exact dialog now the other place you can go and this is where i like to do it this is a matter of personal preference and you'll see why later in this video there's an add to source control option at the bottom of visual studio go ahead and select that and you'll see git shows up and when i do that it's the same exact dialogue so as you can see there's just lots of ways to create a git repo for your project no matter where you are in the product so now we can choose local only it's going to ask the path name i'd leave that as a default because really this is the path for the project that we're working with okay so i'll choose create now we're in source control and i'll show you how i know first of all there are these little lock icons next to the files and if i hover over them you can see it says checked in here okay how do i know that it's in source control especially if i don't see the locks well this brings us to why i like to create my get repo from the bottom because it reminds me that there's a whole bunch of information down here at the bottom of the screen now what you can see is there's a little icon next to my project name which is actually the get repo name too and it has a little diamond shape with a get icon so i know that i'm in get also next to that is the word main with these two arrows pointing out now git and github are changing their product to default from what used to be called the very first branch is called master and they've slowly been migrating to the word main so you might see main you might see master just know that they're synonymous you could actually change main to whatever you wanted you could just say my first check-in but that's probably not a good idea because you know other people won't understand what that means necessarily now let's come up here to the view menu and take a look at one more thing before we get started and go to the git repository option and here you can see that here's this main being created and also a dot git ignore and dot get attributes file was created now git attributes defines one of the what are the features that you want to use with git there's a lot of configuration options we are not getting into that in this demo usually you can just leave that as is until you really get started and decide that there might be some changes you want to make and this dot git ignore file make sure that you don't put things into source control that don't belong there for example passwords or secret keys uh secret key files so these are the files that were added but i'm going to take a look over here at the solution explorer and say wait a minute where are these.kit attributes and dot git ignore files i don't see them here well do keep in mind that the way visual studio works 2019 is that it shows you this view in a way that makes sense for your project for example there is no such thing as a folder called connected services here visual studio is giving us a look into our project because it knows what c-sharp is and it knows some of the things that we need for example also dependencies are files that our project is dependent on but that's why there's no lock because it's just representing some things that we need to put into our code so how do i see the duck get ignore inducted attributes well we can come up over here to the top of the menu and you'll see that there's a little switch views icon and when i click on that now it's opening up the folder structure for our project and now you can see it says folder view up here i can double click on the folder and now you can see there's dot git attributes and there's dot git ignore and now i'm looking at this as if i were doing the following looking at it in here so you can see here is the folder that i'm working with in explorer okay so to get back to my solution explorer view it's a little bit odd i have to keep clicking around for a bit here and then i can just double click on the solution file and that brings me back before we make any changes to our code i just want to walk you through what we're going to do first we have this main branch and that's what we're starting with and from that main branch we can create little branches off of it to create new features to fix bugs and then we can go and test all of that make sure that it's the way we want it to be and then when we're ready we can just merge that back into the main line so the main line or that main branch is kind of the place where your production level code always sits these other sub-branches are you working on things that may or may not ever make it into the product now we're going to create a new branch and also modify some code now i closed all the code windows that i might have had open previously so it's the same project i'm going to go down here to the bottom right and notice if i come down here and click on this main or master you see new branch and up here at the top you'll also see the get menu where you can also choose new branch these do the same exact thing remember i like to go down here because this is my only place where i know exactly what branch i happen to be on so the more i do down here the more useful this becomes so i'll choose new branch and i'm just going to change the create a new branch that's called change title text and i'm putting dashes in between that now you can see here it says based on main so it's going to say take a snapshot of wherever main is right now and create this new branch and also check out to that branch meaning once it's created go there so i'm just going to go ahead and create this so a new branch got created and now you can see that we're checked out to this new change title text if i click on this you can see there's the checked out branch we're on and i can go back to main if i want to so you can just switch between branches as you need to now i'm in the change title text branch and i'm going to go ahead and do just that change the title text i'm going to open up startup.cs and i'm going to scroll down here and you can see there's this hello world and i'm just going to rename this to hello first modified code and save that now once i save that you'll see there's a startup.cs file with little check box next to it and it says pending edit the other way to see this change is to come over here to the get changes tab and remember you can always go to the view menu and choose get changes to turn that on so here we have this startup.cs file if i click this undo changes it makes an undo of every change that i've made ever since it went from a little lock okay remember it had a little lock next to it before all the changes that i've made up until i commit this code change i can undo it so it's not like a control z this is like undo's anything that i did in the file and then you'll see this plus sign this is so that you can stage the change right now git recognizes that this file did have a change associated with it but it's not necessarily logging that okay so if you really want to kind of log that this is a change before you commit it you can don't worry about staging on stage at this point in time if you're just getting used to visual studio this is not something you need to get familiar with so i want to go ahead and make this change formal so i'll just come up here i'm in the get changes tab and i'm going to type a message and say you have to type something very simple and straightforward usually a good idea when you're making a code change like this to use some sort of an a verb or something that represents that you took an action on something so i'm just going to say modified hello world text and i'll just say even to hello first modified just something like that and i can go ahead and commit this change but before i press this commit button you'll notice it says commit all so if i had changed a bunch of files it would commit all of those there's also these stash commands you know what i'd suggest that you do is just get familiar with using this commit all commit all your changes so i'm going to do that now git has recognized that you want this code committed it's put this commit message up here which we'll look at that in just a minute but you'll notice every single commit you do has its own unique identifier and if i go into the solution explorer you'll see a lock and that means it's checked in so that means this is the latest code change now here's what's kind of nice about git is that since we're in this branch and it's a snapshot of the main branch i can just run this code and you can see the text says hello first modified code and if i come back down here to the branch that we were originally working on which is main i'll go there you can see the text automatically change back to hello world because main has the production code the branch has a change so i can even run this and you can see it says hello world so we have two pieces of code that will run differently based on the branch that we're in in order to take our new code and bring it over here to the main line what we need to do is merge the branches so here's how i'm going to do that i'm going to come down here to the bottom right where it says main and choose manage branches a new window appears and main is selected and you can see all the history of the branch right here if i choose change title text i'm just clicking on it once you can see there's a snapshot of main plus the new branch where we made our changes and if i double click on that i can actually get into what exactly occurred and you can see the startup.cs file was modified so this is the commit details that occurred for that branch okay so now what we want to do is move it over i'm going to go ahead and close this commit details and i'm going to go to solution explorer and i'm just going to make sure i open up startup.cs remember we're in the main branch and we see the word hello world and that tab is right here now what i want to do is take the change title text branch and move it into main i'm going to right click and choose merge change title text into main in order to do this you have to have main selected okay so if you're not in the main branch you're not going to see this as an option so i'll merge that and say yes you'll see a commit message up here and now when we go and close this get detail away you can see that the startup.cs no longer says hello world it says hello first modified code cool so now we have an opportunity to run this and the main line the production branch the master branch is going to show us exactly what we're looking for and there it is our new code change has been committed to production it says hello first modified code anytime you are working with your code you're likely going to want to look back at what you originally wrote and compare that to what you are writing let's take a look at how we do that first we're going to go to the main branch and create a new branch and i'm going to call this code dash comparison and again we're going to create this right off of the main or master branch and we'll check out to it so we can get coding right away okay now the code comparison branch is displayed that i can see right down there in the bottom right and we're going to make a code change i'm going to change this from hello first modified code to hello second modified code and save that once again we've made a change in the branch we have a little pending edit check mark here which is great and now i want to see what's going on and compare that to the original code so i can do that in a few ways one is i can come to the get changes tab again you get that from the get from the view menu and select get changes and you can just go ahead and select this right click and choose compare with unmodified but i don't like to use the get changes tab because it kind of pulls me out of the code i'm working on so more than likely you're going to want to do that via solution explorer and that's the same thing you right click on the file choose get and choose compare with unmodified so i'm going to scroll up to the top here for a moment before we get into this what you're looking at right now is the original code on the left and your edited code on the right now what you'll see here on the scroll bar area is there's a little bar saying there's changed code and over here on the right hand side with our new code that bar exists but also you can see this green portion here that says there's new changes so you can scroll on either one of these notice that the code changes no matter which bar you use and let's scroll down here so immediately as i'm scrolling i can see there's a clear thing here that says hey this line has some code changes you can see that over here too now the red means this is the original this is sort of a dark maroon that's being displayed this might be different for your version of visual studio depending on the colors that you set up and over here the green says it's new so let's go ahead and take a look at that as i scroll to the right you can see it all also syncs up so i can change this i can use the scroll bars on the left or the right so not only do we get the line that says this color that says the line has changed but we can also scroll over and see exactly what's changed you can see this box around the text that says hello first and hello second now let's pretend we made a mistake in our code and we need to revert back so i'm just going to go ahead and close down all of the code windows that we have here and go to get changes again and then going to commit this new startup.cs file that has hello second in it and i'm going to change this to modified hello first to hello second and i'll commit that and once again i get a commit message and i'll close that now you're looking at the code and you're opening up startup.cs and you're looking at the change and you say oh wait a minute this is not a good idea i need to go back to hello first so here's what i'm going to do i'm going to go to the get menu and choose view branch history but remember once again if i go down to the bottom right i can also choose view history it doesn't say view branch history but it's basically going to bring me to the same place okay so now i can see here i have this code comparison branch that i created and if i double click on that i can see the various changes that have occurred and this is my commit for the startup.cs file what i can do is just choose and by the way you can see that right here it says modify hellofirst to hello second so what i can do is just choose this revert option right here and it's saying do you want to revert and you say yes and you get a revert message i'll close that also in this code comparison sorry the history area you might notice that it didn't look like anything happened you will have to refresh sometimes you can use the f5 key or you can press this refresh icon and now what you can see is that not only did we modify the code but we also reverted it because it was a mistake so how can we test that well that's pretty easy what i can do is go back to solution explorer and i should see hello first and not hello second again so there we go there's hello first so you've just gone back and removed some mistaken change there are two common misconceptions with git one is that you're only looking at the changes of your code actually you're comparing your new code to a snapshot of code so you are increasing disk size fairly significantly but you know when we talk about this size we are talking about text files so it's not usually that horrible but the other misconception is that you should never delete a branch well in our case we just created a branch to look at some code changes that we decided we did not want to do and we reverted them so what's the point in keeping this if that was a point of the branch originally so you can decide if you want to keep it or delete it personally with my git workflow i tend to delete older branches or delete branches that kind of went nowhere so that i keep it nice and clean but again this is going to be your choice so let's go ahead and delete this code comparison branch click on we'll just go ahead and close all the items here and once again i'll come down to the bottom right and i'm going to choose manage branches and of course i can choose that from the get menu and choose manage branches so here we have our code comparison branch and this went nowhere so if i right click on it right now you can see i can rename it but i can't delete it the reason is is that it's selected so we need to check out to another branch what i'm going to do is just check out to the main branch i'm going to choose right click and choose checkout and of course as always i can always come down to the bottom right and select a branch too so now that i'm checked out to the main branch i can find this code comparison branch and just delete it by right clicking and choosing delete and i'll click ok there now it's been deleted and i'm also going to refresh the history on the marine main branch notice that that whole code comparison branch that we created it does not exist in here that's because we deleted that and we also deleted the snapshot so now we've freed up some disk space but we've also cleaned things up so we know what important branches there are to look at while i did describe why it's useful to create branches i also want to let you know that modifying the main branch is the same way as modifying any other branch let's do that right now i'm going to close down this change view i'm going to go to solution explorer and open up startup.cs and i'm going to just modify the code from hello first modified code to hello changing code directly on the main line and i'll just go ahead and delete this here okay good and save that code now what you can see is the same exact thing as before is happening we have a little check mark saying that the code has been changed i can come over here to get changes and enter a commit message modified hello world hello first rather to hello changing main line commit and the commit was successful close that and now our new code is in place so if i go back to the solution explorer you can see there's a little lock and if i run this you can see it says hello changing code directly on the main line so the fact that this is the main line and we talk about how important it is it's no different than modifying your code on any other branch earlier in this video i said this is thing about stage and unstaged changes and then you also have the committed changes i'm going to show you something that's really important for you to be aware of and that's how this uncommitted changes works let's go ahead and create a new branch i'm going to come down here and click on the main item down below and choose new branch and i'm going to create a new branch called uncommitted files and it's going to be on the main branch and we'll check it out immediately you can see we're on uncommitted files i'll come over here to the solution explorer and i'm just going to close down startup.cs i really want to highlight this problem that you're going to run into so i'm going to do is right click on the project and add a new item and just to keep this easy i'm just going to go ahead and choose html page the point here is not to create the html page but is to show you the problem with working with data that's not committed yet so if i come over here to get changes you'll see that there's this html page and there's a letter a that says that it's been added i could have just as easily modified a page but the point here is that it's not been committed yet because it's still listed as a change so let's come over here to the bottom and click on the uncommitted files branch and move to the main branch and we'll go to solution explorer here's that html page why on earth is this showing up in the main line i didn't put it there well right now get and therefore visual studio is assuming that this file is something you want to create but it doesn't know where you want to put it it's not until you commit that it actually puts it somewhere so that's why you have to be super careful i'm going to go back over here in maine and check out two uncommitted files you have to be super careful what branch you're on while you're working that's why i love working with this item down here in the bottom right so now we can go ahead and click get changes and i'll say add html page and commit that i get my commit message and when i come back here to a solution explorer you can see there's a lock next to it now and that same exact thing would have happened if i had just let's say modified startup.cs now let's go back to the main line i'll click on uncommitted files and check out to the main line notice now that that html page is gone it's actually just in the branch i was working with so i'll go back to uncommitted files and there's that html page that we have throughout this video i've been saying that your default branch will either be called master or main well in order to change that so it's the default that most of the services like github get lab any of the online server based versions of git they're starting to use the term main so if you want to set that on your computer you have to do that manually now at some point this might change but right now what you want to do is go to git dash sc and download the latest version of that code then install it once installed you'll notice that git dash scm has some excellent documentation you can see here there's a documentation link and then there's a book and in here it says installing git and it explains how to do all of that so if you have any questions you can look that up you can also come over here to first time get set up this is where you can do things like set your username and your email this will show up in get commits so just be aware you want to use something that you're comfortable sharing if it goes outside of your computer and the other thing that you'll notice right here is it says your default branch name and you can see here git defaults to master but many other companies are switching to main so you can copy this line here and i'm assuming that you've downloaded git at this point you go to the command line so you just type git in your start bar and paste this in and once you do this there should be no errors so now any new time that you create a project in visual studio it's going to use this main and of course if you wanted it to be master you type master and now any new project you create in visual studio will use master now of course i'm going to keep this to main like that but of course you could just say like bills branch okay so you can kind of type anything you want but i will warn you this is a bad practice because all the training and material online isn't going to talk about this custom branch name that you created so stick with master if you want to stick with the old way or maine if you want to stick with the new way and that's going to help you with training in the future this video talks about using a local git repo my next video will cover how to work with a remote repo specifically github thank you for watching this video if you want more like this please like comment and click the bell to support my channel you
Info
Channel: Bill Raymond
Views: 34,718
Rating: 4.9727893 out of 5
Keywords: visual studio 2019, new git user experience, git user experience, git, source control, Bill Raymond, agile in action, cambermast
Id: gkDASVE_Hdg
Channel Id: undefined
Length: 35min 33sec (2133 seconds)
Published: Thu Jan 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.