Using Git & GitHub in VSCode: Branches, Pull Requests & Merges

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in this short video we're going to be covering the concept of branches and pull requests in git so in the last video which I'll be linking down in the description below we already had a look at what staging committing and pushing means and in this video I'm going to give you a very brief reminder of what they were and then we're going to look at branches and pull requests so on the screen you can see on the left hand side I have my editor open with the test.pi file which only has one comment that says this is a print statement and a print statement that says hello world and on the right hand side I have my GitHub open and you can see here I have the test.pi file and if I open it up you can see that both these files on GitHub and locally are identical if I now decide to make a change to this file by changing the hello to a goodbye for instance you can see that this change pops up on the left hand side under the changes ribbon I can even go ahead and open it up by clicking on it and you can see that on the left hand side it shows me what I had before so the hello and on the right hand side it shows me what I have after which is the buy the new version to Stage this change in order to make it ready for a commit I can go ahead and press on this plus icon right here you can see as soon as I press it the change that I made jumps under a new ribbon called staged changes and the cool thing about staging is that even if I have a lot of changes only the stage changes will be added to my Snapshot that I create with my commit but now we're going to commit the stage changes by adding a message such as update and pressing on Commit and once that's done we also need to make sure that we sync the changes to our remote version that we have saved on GitHub and this process of synchronization is called pushing you can see that if I hover over the sync changes icon it says very small push 1 commits to origin master and that means we're pushing it to GitHub because that is where our Master is saved and so now once we have pushed everything to GitHub we can go over and refresh the GitHub site and you can see that now the code is updated and it says buy World instead of hello world which we had earlier so now as promised we're going to move on to branches and pull requests usually when we have very large projects we don't want to push our changes directly to the master branch and that is because the master branch is your most important Branch as that is the one that is being used productively so that is the one that the customer sees when he opens your site and you wouldn't want to make the mistake of pushing something to the master branch that you don't know is a hundred percent correct and that is where branches come in branches Branch off from the most important Master version and and you can play around on them as much as you want to and when you're sure that everything works you can merge it back into the master Branch by creating a pull request all of this is easy to understand if I demonstrated once so in the bottom left hand corner you can see that it says master and if we click on it we get a drop down that drops down from the top and we can create a new branch which is what we're going to click on after that we need to give the branch a new name for Simplicity I'm simply going to call it Branch now you can see that our user interface has changed because on the left hand side it now says publish branch so to give you context we have created this Branch locally on our file system but we want to publish it to GitHub as well so let's go ahead and press on publish Branch now once that is done I'm going to refresh the window that has my GitHub open and then I can click on the master and below the master Branch you can now see the branch that I just created so this Branch over here is the one that we just sent to GitHub let me go ahead and click on it and you can see it has the exact same code that we have open in the editor with our most recent version that we had also seen in the master version you should also be aware of the fact that any changes that we now commit are going to be made to the branch that we created and we know that because if we look at the bottom left hand corner it now says Branch instead of Master down here so I could go ahead and go back to the master but we're going to stay in the branch for the moment so now let me go ahead and make a change let me write by friend instead of world and then let me go ahead and save this change and add a commit message such as update and then committed and of course I need to sync my changes as always so now something interesting is going to happen as soon as this changes run through I can go ahead and refresh my GitHub and you'll see that on the right hand side it says my friend which is the change that we made and you can see in the window on top I'm still in the branch but now if I go ahead and change back to the master you can see that we have the original version which would in effect be the productive version that the customers see and it does not have this change that I just pushed so I could now go ahead and make any number of changes in the branch that we created and that would not have any effect whatsoever on what the customers see because they see what is in the master Branch but now let's go back to the branch which we created so I'm going to click on Master over here and then down in the drop down I'm going to click on branch in our GitHub and now let's say that we want to make sure that the changes we made to the branch are merged into the main branch we can do that by creating a pull request to create a pull request we can simply in GitHub click on pull requests and it will automatically detect that we have created a branch and we can go ahead and compare it and create a pull request so let's click on the screen button and then over here it says that we can open a pull request you can see that we have the branch on the right hand side and on the left hand side we have this arrow pointing towards the master Branch so in other words it's saying that the changes we made to our Branch are going to go into the master branch and it says that we are able to merge so then we can simply go ahead and create a pull request and once we click on that it is going to check for a couple of seconds if that works and after that we can click on merge pull request and confirm the merge in the next window and then you can see that now we have the option to delete the branch if we don't need it anymore but since we have already made this change it doesn't matter we can leave it I like to leave them for just a couple of weeks to make sure that if something breaks I still have the branch but in any case let's now go back to the master Branch for one moment and you will see that as soon as we go to the master branch and we view the code within the master branch you can see that it has now taken all the changes that were in our branch and updated them so remember the change we made we said um friend we exchanged it for world for friend and you can see this change is now reflected in our main branch so in summary we create these branches in order to test our new features and work on large developments that we don't want to send to our Master directly and when we're confident that the branch is working correctly and that the feature has been developed correctly we can go ahead and create this pull request which takes all the changes from the branch and puts them into our Master Branch if this video has helped you out then let me know by leaving a like rating down below let me know in the comments what other things you would like to learn about next and as always see you in the next video
Info
Channel: Max on Tech
Views: 5,052
Rating: undefined out of 5
Keywords: staging, merging, pull request, commit, branches, tutorial, VSCode, GitHub, Git, Version Control, GitHub Basics
Id: Dedz4gRHezg
Channel Id: undefined
Length: 8min 16sec (496 seconds)
Published: Sun Aug 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.