Github + Visual Studio 2022: Basic Workflow For Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] the first thing we're going to do is create a new project and to keep things simple i'm gonna choose a console app but this flow would be the same for any type of.net project then i'll pick a location in my computer and i'm picking my study folder where i keep all my test projects and i'm not going to create a new folder because when you create a project in.net it already creates a folder for you then i'm going to pick a name that's going to be coding tracker which is one of the projects in the c-sharp academy and hit next and create so the project has been created and the first step will be to create a git repository and it's super easy you have to go to the git tab right here on top and choose create git repository and this window is going to pop up with all the details of where your project lives and the details of your account and i'm getting this message saying that coding tracker already exists so i'm going to change the name to make it clear that this is a study repository and of course the name is totally up to you but i suggest you try to keep it consistent and have a naming system that makes things easier when you want to search for your repositories and by default the private repository box is ticked but you can make it public and let's make it public for this tutorial then hit create and push button which means that not only your repository will be created but the project will be already uploaded then we can go to the actual repository on github.com and you can see that i have a bunch of repositories here and if i type study on the search box all the repositories that have studied in the name show up which is very cool it makes it really easy to search for repositories and here's my repository right at the end of the list so let's click on it and all the files are here we can see that it was updated a few seconds ago and it even includes the git ignore which is a text file that contains information about the files that i don't want to upload to my repository and that was created by default by visual studio so now that our repository is ready to go let's make our first change so i'm going to say console.writeline hello c-sharp academy and as soon as i save my changes on the git changes window i can see that the file was modified and this window is going to contain all the files that have changed and we can see that this m character means that the status of this file is modified and before pushing the changes to the repository first i have to commit them and the commit is a snapshot of your repository it has a unique id and all the changes in relation to a previous commit and all commits need to have a message that's mandatory and always make sure that your message is really clear even if you're not working with someone else that's going to make things easy for you in the future once you hit call me at all it means that the changes were saved to your local repository so they are still not in the github servers so you need to hit the push button and once you do that your changes are finally stored online so if i go back to my github page i can see the latest changes and the message that i created in my commit and here we can see hello shop academy so now i'm going to click on the edit button so i can modify this file and i'm going to say hello c sharp academy one more modification and that's gonna be an actual commit as well so if i scroll down i can see the commit configuration and then i'll hit commit changes so we can see that the file was successfully modified so let's go back to visual studio and obviously i still don't have these changes locally so now i'll hit the pull button and pull it means that i'm going to bring the changes from the repository in my local project will use the latest commit so once i hit that button my file will be modified so it's going to contain the last change in the last commit now let's have a look at fetch back to my file i'm going to copy and paste my statement multiple times just to make it easier to visualize and then i'll commit with the message now we have many messages and hit push to the repository then back in my github page i'm gonna edit my program.cs file again so i clicked the edit button and again i'm gonna keep just one statement and i'll make a commit with the message keeping one message then i'll hit commit and back to visual studio i'm gonna hit the fetch button and what that does is it brings in the latest commits but it only makes them available locally so it doesn't check your local repository out to the latest commit and to visualize a list of all the commits in our project we can hit the view branch history option in the git tab and that will open this window with information about our previous commits and this is the commute that i did remotely in the github website and we can see here in the incoming tab that there is one commit and this is one of my favorite areas when working with it in visual studio i spend a lot of time here there's a lot that we can do and if you click on the commit you can visualize the differences between current and the previous commits which is extremely useful for your workflow what was deleted is highlighted in red and what was added is highlighted in green and if we go back to the list of commits and hit pull our project will be using the latest commit so if you hit refresh we can see that the commit is now part of our local history and our project is using the last commit now in case i don't like my changes i have a couple of options to revert them if my changes are already in the remote repository the easiest way is to revert them so if i click on the revert button i'm basically creating another commit undoing all of the changes the last commit and when i confirm that change we can see here that there is a message revert completed and committed so now we have a new commit a reverted commit and all we need to do is to push it once we've done that and hit refresh we'll see our latest commit which has as a message revert the name of the previous commit if we go back to the github page we can see that the revert was saved to the remote now in case our changes are only local we can do a reset instead of revert so let's modify the file and do another commit so this one will have as a message i wrote a method so now it's committed and let's go back to the branch history so we can do a reset we can see the latest commit in the outgoing tab and that's because it hasn't been pushed to remote yet now if you right click on the previous commit and choose to keep changes the latest commit will disappear but the changes will remain so let's click on that and then refresh and we can see that there is no more outgoing commit but we are keeping our changes so let's commit these changes again and again the message will be i wrote a method and if this time we right click on the previous commit and choose to reset delete the commit will also disappear but we also lose our changes we call this a hard reset so always be careful with these because you might lose your changes but now let's have a look at branches another one of my favorite features of git so let's write a bunch of new changes i'm gonna write three new methods and save and then i'm gonna create a new branch so here i can choose new branch in the git tab so we're gonna be presented with a dialog and we can choose the branch name and again make sure your names are consistent and clear personally i like to enumerate my branches to keep things organized and you can also choose which branch your branch is going to be based on right now we only have the master branch so that's not really a concern but that's very important when you're working in a repository that has multiple branches then you're presented with a few options and that's because before creating the new branch i have changed the previous branch so i'm being asked what i want to do with those changes and one of the options is to stash those changes which means that i'm saving them but cleaning my files back to the latest commit in my case i want to bring the changes with me and since this is the first commit of this branch i'm going to say initial commit and then commit and push my changes [Music] back to the github page once i refresh i can see that there is a dialog with all my branches and the reason why i really like working with branches is because they are quite independent from each other so it's very easy to navigate into a new branch to visualize the state of my repository at any given time if i click on my new branch i can easily navigate through my files at that stage so back in visual studio if i go to manage branches i can see a list of all of my branches and i can easily change my current project into one of those branches and that's a bit harder to do with just commits so if i click on master i can see that my project is now in the previous state and if i click on my second branch the project will have the corresponding state again and it's important to notice that even though it's a new branch all the commits from the previous branch which this branch is based on are also part of this branch now the last step is cloning a repository into your computer in my file explorer i'm going to delete my coding tracker folder then i'm going to restart visual studio and choose clone repository and i can click on the github option to navigate through a list of my remote repositories then choose coding tracker then choose this study folder again and hit ok then when i click on clone the project will be copied to my computer and notice that the name of the folder is the name of the repository previously i just had coding tracker as a folder but now the folder is the name of the repository now just before we finish here you can see where i keep all sorts of notes and that includes notes related to programming and i have a section dedicated to git so whenever i realize that i'm using the same commands over and over and always having to look them up i put it in this list so i can quickly look it up when i need it and the last tip is to search when you want to find out how to do something with git so here's an example of something that i've recently searched how to merge two branches and i can always find a bunch of answers especially in forums like stack overflow just bear in mind that there are hundreds of commands in git and visual studio doesn't support all of them so sometimes you're gonna have to use the command line so that's it i hope you enjoyed the video please hit subscribe and please comment below if there is something else you would like to know about git in visual studio and don't ever forget to save your changes see you next time
Info
Channel: The C# Academy
Views: 23,587
Rating: undefined out of 5
Keywords: c#, beginners, .net, absolute beginners, tutorial, learn to code, coding tutorial
Id: oCvb-Q5lXb8
Channel Id: undefined
Length: 11min 24sec (684 seconds)
Published: Fri Aug 26 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.