The Git Flow - A Guide to Using Git Effectively for Beginners - Crash Course on Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right today I'm going to be showing you the git flow and a guide to using git effectively this is what I consider the cycle of using git and we're going to be using GitHub today to actually host our repo so one quick mention I want to make if you watch my last video which you should have done I'll post a link in the description below that was on how to set up a git repository in GitHub so you can get to this portion of git flow so you know how to use git effectively what is git again this is a tool to help you track changes in your source code with Version Control basically the underlying tool to help you manage your repository GitHub is a web-based repository which helps you actually host and store your files and code so this is just a hosting platform now that we need to understand the difference between the two let's continue on with the get flow and how to keep track of your code effectively so first off if you haven't already check out my last video on how to create a new repo because you'll need a cloned down repo in order to be able to do the following so I'm already in my repository I've created a file inside of it I'm going to be updating this file and showing you how typical developers follow through and make multiple changes in one base code while simultaneously working on different parts of the code and then merging them back together the first thing we have to talk about a little bit is really a tree branch type of hierarchy here so we basically have like the trunk of a tree you would imagine and then you could have different branches off of that tree well I like to call the trunk here Main and then anything off of the trunk we can call branches so we can call this Branch one two three so on so forth so what's the nice thing about these branches well the branches in git call them get branches allow you to Branch off the main trunk and create and change your own code and then merge it back into main so what does that look like well if we had a main trunk and then we said oh I want to create a branch and I'm going to call this Branch like a front end feature so I'm adding something to the front end while someone else is working on the back end we can both be working on the code simultaneously in different source files and then we could both merge back into the trunk at some point without interfering with our code and keeping up to date with the main branch or trunk so now that you kind of understand what branches are let's actually use one first off if you ever want to list the branches that are currently available you can type in get branch and that'll show you where you're currently at and what is available right now I only have the one branch which is main so I want to create a new Branch also don't forget to be inside of your repo notice that I'm in my git flow repo here locally and I'm going to do git checkout space Dash B and then a new Branch name so so I'm going to call this new Branch just so we can follow things through fantastic it says switched to a new Branch so what does that look like well if we do get Branch again this is a good friend of yours notice that now New Branch is green main is in this white color and we have a star near New Branch that means we're currently located in New Branch and that's what we're making changes of and when we created that branch that also took what whatever was in Maine and is considering that the latest and greatest code that we're working so here we can now make code changes I'm going to actually make a change to my main cpv file and I am going to say something else here and now I've added a branch so that's what I'm going to say here and to clean things up I'm just going to put a new line character at the end of both of these just making a little bit of an improvement I'm going to save and now if I do get status again get status is your friend it says oh there are changes that have been made main cpb has been changed in order to add this sin will have to use the add command but to check what's changed in a specific file you can do git diff and then type in the file that you're looking at and look at that it says this was removed this was added or changed and this was added or changed so that makes sense added a new line to this line and then I created this new line entirely fantastic that looks like the changes I made I don't need to add any more files necessarily but if I do get status I do have to add the modified version of main CPP so the next portion of this is to add in your changes so I'm going to do git add and I'm going to add in the files that I've changed if you have more than one or you want to include a bunch of them you can just use asterisks where necessary either in the extension hitting get add main.cp that after I do it I can check the status once more and notice it says modified these changes are are ready to be committed they're staged and now this is the time where I commit my code so I can do git commit I'm going to do a message and I'm going to put added a new line for the new Branch that's just my message again think of this as little summaries that help you or team members remember the changes that you had made and pushed to the online Branch so I'm going to hit enter and it says that new branch has this commit one file changed two lines inserted one line deleted fantastic finally the last thing I need to do is push my changes to my Branch so I can do git push and then I'm going to do set Upstream I'm going to type in origin and my new Branch name yours of course doesn't have to be new Branch it's whatever Branch you're currently working in and then you press enter and I forgot two dashes here anyways there we go and that's it as far as finishing up the code for this new brand now it's telling me create a pull request for the new branch on GitHub by visiting so I suggest someone from your team to actually look over the pull request to check your code but let's go back to GitHub so we can check what this poll request means so right here it says new branch has recent push changes that were made a minute ago if you don't see that you can go into your branches and check for it so if I go to branches I have new Branch fantastic it'll it should show up here as well but let's check out the main branch so if I just go back to get flow notice it says there's been a change here 15 minutes ago well that's not the latest change that I've made the latest change is still in a branch located away from our current main branch so if we draw that out that just looks like this we have main branch or trunk and then we have this new branch that we created and right now they're forked away from each other meaning Maine does not include the changes of the new Branch how do we merge these in well that's by creating a pull request and merging the changes in so that's the next step I'm going to hit the compare and pull request I'm going to leave a comment if I have one and just keep the commit subject the same I'm going to create a pull request and then what's going to be checked is if the code can be merged in without any changes well it can that's because there are no conflicts the way a conflict could happen is if two people in two separate branches have made changes to the same file or source code well then the repo won't know which portions of the lines to keep from the same file you'll have to actually reconcile a merging conflict online if that does happen but anyways if you're doing this right you probably won't get that I am ready to merge this pull request if someone wants to review your code they can go to the commit they can actually click on it and see the changes you made if that looks good they'll hit review changes they might set approve or request changes or put some comments in anyways I know everything's okay here I've been given the green and I'm going to confirm the merge okay this has been merged in next it's time to do a little bit of cleanup delete the branch that way it doesn't exist here anymore no one can mistake it and people can reuse that name and then in the main branch I'll notice oh look at that added a new line for the new Branch it had been added five minutes ago and that pull request was finally merged in to Maine from the new Branch congratulations if you did this you've effectively used the git flow and the way git was intended to be used to keep track of your git repository in GitHub I do want to show you how to make another change now that we are finished we can do get Branch again notice New Branch locally is still here and we should also clean this up so let's first change our Branch to main so git checkout Main and we're now switched over to main I'm going to type get branch and New Branch is still here that's because this is a local branch now it's been deleted online as we deleted it a moment ago on GitHub but these two are not in sync so I need to delete it here locally as well but I'm not going to do this until I do a git pull because since we made changes to the main repo and we never actually took those down to this local git repository we need to do that notice how when I did get pull it pulled down Main CPP and made those three changes that we had one was a file change one was two insertions one deletion makes up three in one file that was changed fantastic I have the latest main CPP file now I'm going to actually clear things out and finally delete that Branch so get brand inch Dash D and then I'm going to specify the branch I want to delete I'm going to delete the new Branch that's it it's deleted if I do get Branch I shouldn't see anymore I don't I'm in main I got everything pulled down and I'm ready to work again on my local project fantastic work let's go through it a little quicker this time so that we get the flow of things this time I'm actually going to create a new Branch I'm going to get check out Branch I'm going to call this one organize I'm going to do a little bit of organization here and I'm going to check which branch I'm on I'm on organize fantastic I'm going to move my source code and create a readme file so first I'm going to do read me that's going to be a markdown file and in the markdown file I'm just going to put here this is to show the flow of get with GitHub save and exit out of there so now I have a new readme file then I'm going to and actually I want to capitalize all that so I'm going to just do readme.md okay fantastic and now I'm going to move my main cpp5 file into a source directory so I'm going to first create a new directory called SRC for source and I'm going to move main CPP into Source fantastic so I just have a readme file a built file and a source file next thing I'm going to do is I'm going to do git status to see all the changes that have been made it says it realized I deleted main CPP that I created a readme file and a source file so the way I can accept these changes is first I'm going to do git RM for remove and I'm going to remove main CPP next I'm going to do git add and I want to add everything that's in source so I can just do source with a star star means use everything at least inside this directory called SRC that should have added everything and finally git add and I want to do just the readme file in the main local repo and then I'm going to do git status look at that it says renamed main CBP has gone into Source main CP fantastic that's what happened readme.md is a new file it's been added and we're not keeping track of the main output file we don't need to actually what I'll do in that one is I'm just going to remove main so it doesn't clutter things up and if I do a git status everything's in green doesn't that look pretty all right so we've made our changes we're going to check what branch we're on we're in the organized branch and since I've added in the code I'm going to link to commit it with the new message and I'm just going to say I cleaned some source files up and now I'm ready to push those changes again get push I'm going to set the Upstream to the origin and send that organize Branch up and again I forgot the second Dash there no big deal fantastic that's been pushed up so I can create a pull request Again by visiting GitHub back to GitHub it noticed it pretty much right away organize had recent pushes less than a minute ago fantastic compare and pull release request and then I'm going to create a pull request it's going to check and make sure there's no merging conflicts there's not and I'm going to merge the pull request confirm the merge after it's been checked and finally delete the branch check my files out and get flow look at that now we have a source folder no more main CBP in the main directory and we have a readme which shows up here this is to show the flow of git with GitHub sweet things are working out and now you're starting to understand the git flow we're again going back to our local repo and let me do a little bit of cleanup one more time I deleted the branch online but the branch still exists here I'm going to first do git check out change back to Main and I'm back in my local repo I'm going to do get Branch notice I still have organize here and Main I'm going to switch repos so get check out main okay should be back into Main and I'm going to get rid of organize if I do get branch that should be gone I'm back in main I have the latest changes pulled down fantastic work I hope you enjoyed this get flow tutorial you're ready to create a new Branch again and make even more changes to your repository this should help you work with multiple people on a project and even contribute to projects that are currently available if you're more of a person who likes to read along and follow I do have a blog post on this I'll post it in the description below so you can check that out as well if you want it makes it easier to copy and paste things and read at your own pace if you're one of the 95 percent who hasn't already subscribed Please Subscribe below you're getting quality content out of this don't forget to like the video catch me in a great community on Discord and I'll catch you in another video
Info
Channel: SavvyNik
Views: 6,116
Rating: undefined out of 5
Keywords: git, github, git hub, source control, scm, git tutorial, tutorial, how to use git, how to use github, github tutorial, how to, full tutorial, learn github, learn git, savvynik, git repo, github flow, git flow, git for beginners, git tutorial for beginners, git basics, git explained, git crash course, git course, linux, github for beginners, how to install git, using git on linux, linux git, linux github, linux git commands, linux github tutorial, learn git version control
Id: zTgXYR4PZ04
Channel Id: undefined
Length: 14min 38sec (878 seconds)
Published: Sat Apr 29 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.