How to use Github with Visual Studio 2022

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this video i'm going to help you work through get which is the system for managing your source code as a programmer so we're going to look at this in two different ways first of all i'm going to teach you how to use this as a student maybe as an individual and then also if you're paired up with a partner in a team how can you trade code with each other and manage it well so that's what's right ahead my name is chad sluter and i teach software development at grand canyon university in phoenix arizona so welcome to class and i hope you learned from this tutorial so let's start with the idea of version control so most of us start off with this kind of a system if we have multiple versions of a program we have multiple folders on our desktop and so as the program proceeds we create copies now this works okay if you're working alone and if you're working with a partner it doesn't work very well at all so get is a source control system which is somewhat complex to understand the first time you see it but once you get used to it it becomes one of the default ways of how you manage your files so let's talk about version control first of all so as time passes you have different parts of your program that you develop so let's say in the first version of your app the only thing that you had to create was a login screen and some kind of a controller to make that happen and then when we have a stopping point like a nice feature is finished we call that a commit so this might be commit number one then later on you create another feature of your program so let's say we add a model a class for a product in our program and so then we commit that to our source control and so on so every time we add a new feature we do a new commit so a commit is kind of like a version number as you go now the nice thing about versioning is that you can back up so if you create a mess you can always revert back to the previous version of your program where you knew things were in good shape and then you can start again from that point so let's talk about some strange vocabulary that you're going to encounter as you use get so you probably are familiar with github which is a website which is handling repositories of code so get is not the same as github github uses the get protocol to manage its files so there are two terms that you're going to see over and over and you need to know what they are right away before you get confused so you're going to see the word origin and you're going to see the word master so origin refers to a centralized repository where you put your code it's the origin where other people can also go and get a copy of that code on your computer you're going to have what's called a master repository so a master is not the same thing as an origin it's actually a copy of the origin now the operations that you use to transfer files are called push where you can take something from your local repository and push it to github and then you can also do a poll from it or clone sometimes if you want to take a copy of the entire repository and so all these are are text files that are being sent back and forth so here's an example of a repository that i have published on my account and we're going to use this in the tutorial in a minute you can see that the file called form 1 is a c-sharp application and it's simply the file that you would see if you were looking in visual studio so this works with html css python c-sharp java assembly you can put pictures in here actually github and the get system doesn't really care what programming language you're working in it just essentially treats everything as a text file so here's another example of a git repository this one here is for a web page and so when you look at the files you can see that they are simply text files written in html format now a nice feature that you work with on a git hub repository is that you can have multiple people working on a single project so for instance let's say you're the first person in line here and your job is to fix bugs and then you have another partner who is adding a new feature such as changing the css or maybe maybe adding a new form or some kind of a feature to the program you are not really working on the same page at the same time but you're working on the same program and so you are allowed to check in check out do pulls and pushes which means that you can both work on the same source code and not have a confusing mess by trading files by usb drive or by email or however you did it before and so using a get repository is really very effective when it when you work with teams so before we get started in actual coding some examples let me talk about what branches are so you can see where we're headed with this system so let's say you have a branch on your computer called the master branch this is what you started with when you did file new project and started coding let's say we have version one already set up which is a login page for our application now i want to make branches because there might be some new work that i want to assign either to myself or to another person let's say i run into a problem where i know there are some bugs to fix and so i might create a branch called the bug fix branch and then i would say i'm going to fix the password error and do a commit or then i might have to merge it at the end so a branch is kind of a side detour and then when you want uh incorporate that into your final product you have to do a merge so literally on your computer when you work with a branch and you type something out and change the code you are not modifying the original you are working with a copy now this works very nicely let's say you have another person that is working on a new feature they're going to add the new product and then an admin page you can have them create a new branch and when they're done they can merge it back into the original and the point then of a get management system is that before that code is re-merged into the main product it can be tested and it can be reviewed and you can see if there's any problems and if there are problems then you can just revert to a previous state and then after rolling it back of course you can get back to a working state of your application so to give you a demonstration on how this works i created a very simple application in visual studio so this is a program that does temperature conversions so if i say 32 fahrenheit to celsius gives you zero and if i want to go the other way such as 100 and go celsius to fahrenheit i get 212. so this here is a very simple program that we're going to modify and show you how the new changes are affected as we commit them to our get repository so let's close this and look at the source code so this is a pretty simple program i'm going to double click one of the buttons and you can see that i have a form design and then i have some code in here which is in c sharp which does the conversions for me now how do i make this work with github if you look down at the bottom corner here you see a message that says add to source control so i'm going to click here and the choice for get is the only one that i have available now i am immediately told that i am going to connect this to some kind of a repository online as you can see github is the choice that microsoft wants me to use did you know that github was owned by microsoft so now i have to log in so i have an account here called shadsluter which is my personal account i'm going to show you a new one so on this account i'm working with an account that i created called professor sluter okay and i'm going to authorize this to connect to my computer so i have to put in the password okay great i got success i've been logged in and so now when i look at my github account i can see that here i am signed in under a certain email address that i've registered and i don't have any repositories yet so let's just put that out of the way and now i have been connected so let's check through a few more things here we've got a professor sluter is the owner temp conversion is my name and it's a private repository and i'm going to create and push this now that act of pushing and creating that did several things first of all you notice down here that this is called master so the default name of your local repository is master so sometimes they would like you to use the word main or master or principle or something to indicate that this is the main thread of work so master is the default let's go and switch over to see what's going on in our github page so i'm going to simply just refresh this page that i'm logged in as and i see a new new repository here so let's go ahead and click it and see what it says so i've got my data here from the forms that i was just programming and you can see the source code is listed so using visual studio all of this is done pretty much automatically you don't have to learn any of the get commands at the command prompt i'll show you those in a few minutes but i want to just show you how it works in visual studio to begin with because it's so simple all right let's say it's time to make some changes to my program so i have a clear button i'm going to change a feature let's say i'm going to change the clear buttons background color so instead of whatever we have here i'm going to select a different choice so let's go to maybe system custom there we go i'm going to make it a blue background and okay pretty simple change right okay so now we've got a purplish button let's see if we can apply these changes to our local repository and then push it to our github remote so i look into my uh solution explorer and you can see i've got new some uh little icons here so program cs has remained unchanged however you can see that there are some little marks here that says pending edit for form1.cs because that was a design change right it was changing the color of something so let's say i want to apply update so i'm going to right click on the project name and choose get and then i'm going to choose commit or stash so we're interested in commit right now when i choose commit it comes up with a message box that says tell me a message and then the changes that are listed below here so what i want to do now is put a description of what i just changed so i put in a message that says i've added a color background to the clear button below that i notice that i have three letter ms next to three files the m stands for modified so get recognizes that this has been changed and it has not been yet committed so i'm going to select all of these so i click the plus sign here that says stage all and it says do you want to save that and of course i do and now i've got myself all the files that are ready to be committed so i've got the message i've added them to the staged area and then finally i choose commit staged now what happened to that did it actually post it to github it did not let's go double check that so i'm going to github and i'm going to the temp conversion folder and let's go look at the form designer and see if anything comes up so if you were to go find the color for this clear button you will not find blue-ish as the background not yet anyway so let's look at some of the small icons here you can see that i have an up down arrow and it says there is one outgoing and zero incoming these are called pushes and pulls so what i want to do is i can either choose a push or i can choose sync it so i'm just going to push the push button and it should send this new commit up to github and so it says your task will continue in the background now when this is pushed we should see the new change so i'm going to go switch back to this page that i was looking at a second ago and refresh it and let's see if we can find something about the clear button so i'm going to press ctrl f and type clear and sure enough we have a text called clear and the back color has a property now so the source code has now been pushed to my repository okay so immediately you should come up with a question is how often should i be doing this committing and pushing so committing should be done quite often and pushing not so much but what you see is a general rule is that when you create a commit it kind of refers to a single version of a single topic for example a commit with a message such as fixed a login issue might be a good example of when you would commit you've done one thing and it's finished however commits that combine multiple things are really kind of hard to work with so if your message gets long such as this one that says fixed a login bug change the color scheme updated the user class to include new properties then you have at least three commits there that you should have done separately so commit when one project or one theme has finished now let's talk about sharing this with a team so i'm going to go back to my temperature conversion and go to the top level so now i'm back to my github page so i want to go take a look at this item and choose settings for my project and i'm looking for managing access because i want to share this with a friend right now it says this is a private repository which is what i set it up to be now i'd like to invite somebody to come and work with me so let's choose add people now i need to know their email address now i've created an account just for this occasion here so i'm going to no longer be the professor but the student so student shadsluter.or gmail.com is who i'm trying to share with so let's go ahead and send an invite and this person then should get an email that says hey you've been invited to join a github repository okay so you can see i see the message at the top that says shed student shed sluter has been added as a collaborator so let's see if there was a message that was actually sent so for this occasion i have set up another virtual machine another computer so student sluter has this dark background on windows and if i were to look in to see what's going on in the inbox sure enough we have a message that says professor sluter has added and would like you to collaborate so let's go ahead and view the invitation and when i log in it says can't find it we have to sign in to github so let's make sure we're logged in first before we can read this message okay so you can see that i have the message now and it says you've been invited well of course i will accept this invitation and see what we can do with it so now i can see that professor sluter has published a temp conversion application and i am allowed to view it thanks to his invitation now let's say i want to work with this i want to put it on my own computer so i have visual studio installed on this computer so let's go ahead and launch it i'm going to work with version 2022 and see if we can open up this project so as soon as i load up visual studio 2022 you can see that one of the options is to clone a repository and i can get it from github is one of my choices so let's go ahead and select that and now i need to know the github location so fortunately that's over here i just take the url that's at the top of the screen and copy that and let's switch over into visual studio and paste it now where's it going to put it it's going to put it on my c drive in the source repos folder which is default and let's go ahead and choose clone okay so the cloning takes a few seconds and you have to be authenticated so there might be a login screen that pops up but what you what you should finish off with is a fully formed project here if we can find it into our solution explorer so i'm going to switch over to solution explorer and see what's going on so i'm going to select the appropriate icon over here for temp conversion sln and let's see if the solution actually pops up and we can run the program so this looks like it may have been successful uh you can see that i have now the form 1 and let's go ahead and look at the see what the screen looks like and so sure enough we've got ourselves the source code and if i'm lucky it might even run and so sure enough it looks like it ran and i even have the purple button as i had programmed earlier now let's say we want to communicate with each other and do different uh parts of the application as a team okay so now let's say as the team member i've been assigned to do a new feature on my program so let's see if we can view this program so i'm going to choose view designer for form one and take a look at what we have already so my goal in this new feature let's say i have to add another conversion so i want to add a new button here that is going to work with the kelvin scale as well as the celsius scale so let's see if we can add that feature so i could just keep working on this master branch that i've already got defined here but let's say i wanted to separate this new feature in a separate branch so let's say we have a new branch called right here so let's uh let's add a new name so i'm going to add mine as k to f feature and let's go ahead and choose create notice it says it's already set for checkout which means you will see that it will now switch to the new version automatically so i have this new item here so if i wanted to switch back to master i can just select select it here and if i want to switch back into my new feature i add it here so now i'm going to program this new button and then we're trying to commit this change back to the main origin eventually so i'm going to write this pretty quickly the important part isn't how to write the code as much it is is manage the github process okay so i'm going to create a new button here and i'm going to put a new label on is f2k and an arrow and double click on the button and let's choose some quick formulas here to adjust the math so that way we can convert from fahrenheit to kelvin and then finally i'm going to run the program and see if it works so i've got 98.6 and i choose fahrenheit to kelvin and apparently that's 310 i'm not sure if i did the formula right or not but anyway i have the new button i have a new feature and it's ready to go back into the main project in production okay so now i've got this new feature included here and notice i'm in this branch called k to f feature what i want to do now is to commit this to the new uh staging area so you can see there's a little check mark that says you've updated this one file so let's do a right click on our project title and i'm going to get and choose commit and then put a message so i'm going to say the commit is going to say added k to f as my idea as my new feature and then i'm going to stage everybody so let's see stage everybody with a plus sign and then finally choose commit staged and i have the new feature in my get repository okay so now let's say i want to share this with my friend i've got the new feature ready and let's go ahead and choose a push and it's going to say make sure that you got the right remote that you're trying to push to so i'm trying to push it to this k to f feature and go ahead and choose the push button okay so now i have a message that says uh you've successfully pushed the new feature to github so now let's go check this out on github to see actually what's there so i'm going to just do a swipe and get to my other computer now so this is now professor sluter's logged in account and let's go ahead and choose temp conversion and see if anything is going on here so any updates sure enough there's something called two branches right there two branches and you can see that i have a new uh branch called k to f feature so i want to include this in my program so let's go ahead and choose pull request so what this is going to do is take that new feature and now include it into my local repository so it says added k to f button and i'm going to say receive from student and she'll go ahead and choose pull request and see what happens so i look down the page a little bit and i get a green status message that says this branch has no conflicts in other words you haven't modified any files that the student has modified if there were conflicts then we'd have a merge issue but right now we can go ahead and just choose merge this and go ahead and confirm it and let's see what happens okay it says now that you've merged this new feature into your program and you're allowed to delete the branch before i delete the branch i'm going to come over here to my program all right let's go check out our project now and see if we can see any changes so i've got the current version of the app and let's go over to the tab that says get changes and go ahead and synchronize this and see if we get any updates okay so i'm going to do a close the file and then do a right-click and choose view the designer and sure enough i can now see the new files have been incorporated into my program here so now let's switch back into the github page where it says your pull request was made and now you can delete this branch safely so go ahead and choose delete the branch and away it goes it looks to me like we've got ourselves just the master now instead of that other feature so we've covered some basic skills here in get with visual studio however there's other things that you don't know yet so for example how do you use the command line with get what other ides such as android studio or visual studio code and how well do they work with git how do you connect an existing repository to a remote repository and for some reason they're not connected already how else do you manage merges so if you and your partner both modify the same text file how do you reconcile those and there's rebasing and forking and so other topics so check out the links below to see what else i've published on get also do not subscribe there's already way too many people watching this channel so i want you to go somewhere else no subscribes no clicking the bell for notifications goodbye thank you very much
Info
Channel: Programming w/ Professor Sluiter
Views: 155,308
Rating: undefined out of 5
Keywords: git, github, git visual studio, visual studio 2022 git, vs git, github git, git push, git pull, branch, pull, push, merge, vs code git, github vs code, github visual studio, c# git, microsoft github, git commit, commit, git message, stage, git stage, git status, git command line, github status, rebase, github visual studio 2019, visual studio 2019, visual studio 2022, vs 2022, git merge, git checkout, git rebase, visual studio git, repository
Id: BWqpTpo1kfw
Channel Id: undefined
Length: 23min 46sec (1426 seconds)
Published: Mon Jan 24 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.