Transcript for:

[Music] hello everyone I'm Landon schlong and today we are going to learn git by building a SQL reference object and it is a version control system that keeps track of all the changes we make to our code base and this is a 240 lesson course so the git is very important to know um people will recommend to get good at git and that's uh very true because you definitely need it to get a job so let's start this course and probably run with code Ally yep all right let us get started with this we have our project open here all we have to do is Echo hello again to the terminal to start out with so that's pretty easy we can just do control back tick to open that terminal up and then we can like then go hello get go hello get and then we can move on with control enter all right it should be in the project folder in the terminal you open use the terminal to make a new directory name SQL reference all right so we can do that with new directory so we can do maker SQL reference reference in the projects folder yep I spelled that wrong awesome I need an underscore there we go now I can move on and I have to remove I can remove SQL reference I think like so.net it's a directory now I can delete it like this though yeah all right that works use the change directory command to change to new folder CD SQL reference there we go git is a version control system to keep track of your code and this folder will be your git repository turn it into one by typing get init into the terminal yep so get init will make it into a git Repository and we use the list command with a flag to list the hidden folders looks like ls-a and there we see we have a git file on there but it's hidden the get init command created the git folder for you it's what keep tracks that keeps track of all the things in your repo use git status to see the status of where you are okay so get status yeah no commits yet uh geek get repo has branches to help keep track of things you are doing with your code it's common to have a main branch that you can create and go to a new Branch with Git checkout B new Branch the dash b stands for branch use command to switch to New Branch named Main all right so to see what branch we're on right now we can Oh I thought get Branch would let us know but apparently not uh let's just do the skit checkout thing get checkout uh Dash B new branch uh actually we want to switch to a new Branch name main yeah okay check out Dash B and then we can do get status and it says nothing on breach mean yeah there we go on Branch maintenance right now you are on the main branch use the touch command to create readme all right so touch breed v.md and then this will describe what the repo is for and the tech SQL reference at the top of your new file I wonder if I can do go to add that SQL reference and then just go to entire readme like that yeah that works awesome let's go check the status of your repo again all right so let's get status still no commits uh actually but we do have an untracked file yep what value created has not um an edit ticket yet so it is showing that is on tracked there's two steps to keep it to get keep track of it for you first you need to add it to the staging area like this get add and then uh add your file name okay so we can do git add readme there we go now now it's added to the tracked files check your status again status changes to be committed is the readme yep so this is the staging area now your file's in staging that will be added with the next commit you aren't quite ready to commit this yet though use Touch again to create SQL reference.json Right Touch SQL reference dot Json check your status again get status and that one's not not yeah first one is staged or yeah the readme stage SQL reference is not staged you have you now have one file on staging and one that is untracked add the new file you create it to the staging area git add SQL reference there we go check your status one more time now they're both staged uh to commit them you use git commit Dash M initial commit the dash m stands for message oftentimes the first commit of a repo will have the message initial commit commit your two files with the message initial commitment all right get commit M finish [Music] here we go uh when you make permit whatever is in the staging area will be added to your git history you can see more info and terminal output above the about the unit to check your status get status oh whoops get status there we go nothing to get working tree clean your working tree is clean the files were committed and there's no other new changes that get recognizes you can see your commit history with Git lock and check your commit history so we can do git log to check our commit history and there we have just our one individual commit and instead of the hash you can see the commit you made it shows the message you gave with commit along with your username email and date and command so the commit hash is this thing right here now the hash is that long string of characters open up your Json file and create an object with a reference for how to create a database that looks like this all right let's open up our Json file and add this to it right here okay paste that in there yeah we should be good to go maybe maybe not make sure there's one empty line at the bottom of the file all right there we go sweet check your status again do that with Git status get status here we go we modified it now it recognizes new on stage changes to your file notice that it says that files modified instead of untracked because the file has been previously committed you can see the changes you made with Git diff take a look at the new changes git diff and there's our changes Suite lines with Plus in front means that those lines were added add your new changes to staging with get add command again git add our SQL reference.json there we go check your status get status and there we see it was modified and it's now to be committed so it's in staging with them with uh that message probably so git add or get commit dash cam and then this message feature add create database reference reference reads cool commit messages often start with fix or feature or feat among others to help people understand what your commit was for check your git log again to see the new commit added get to log I actually never do that really good but I guess it's a way to do it others to commits in your history the newest one is on the top in your Json file add a drop key to your database object okay give it a value of how to drop a database similar to create value the syntaxes and the hints again make sure there's an empty line at the bottom all right add a drop to your database objects create okay so we just go drop here drop is drop database database name I think I think that's what they want yeah okay cool check your status get status here we go it was changed again now I'd check it with diff so git diff and there we see our changes to it um yeah it should show one line removed and two lines added add your changes to staging area so get add and we're adding the SQL reference again here we go commit your stage changes with the message feature add drop database reference okay so git commit Dash M feature add drop database reference there we go I think you're catching on check to check the log again so get log there we go we have multiple commits now three of them in total uh now there's three commits you have been making changes to your main branch you actually want to try and avoid that type get Branch to see the current branches in your repo get branch and we just have our one branch main we only have the main branch you can create a branch with get Branch Branch name branches often start with fix or feature among others like commit messages but they use a forward slash and can contain spaces create a new green stream feature ad create table reference all right so we're going to do git branch and we're just going to add it looks like add create table reference all right cool a new branch is a clone of the mean branch it sends us a branch uh you were on when you created it yep that's very important to know uh it will have the same code in commit history as main did at the time of the branch creation view your branches again with get Branch okay Branch all right there we go we have our two branches now but we're still on the main branch as denoted by the star and the different color we can switch our Branch with get checkout so we check out the new branch and we can switch to it so we do git checkout checkout feature add create table reference and you can't really tab it to autocomplete which is really annoying but uh yeah just gotta type the whole thing out says you switch to your new Branch type get Branch so I can make sure the star switched all right get branch and there's a star on our new Branch like I said you often don't want to make commits directly to the main branch of a repo this Branch will be for some new changes what you will do is make the changes and commits here then merge them into the main branch when you are ready add a reference for creating a SQL table to your Json file alongside your database property make it look like this all right so we want to add a table thing alongside the database stuff so we can go comma and paste this here so I think that saved you control enter show me the stats again you might as well get used to it all right let's get status there we go uh we modified it and we can do get diff to see what the changes were and we just added table okay um enter Q There we go you made new changes to so the file shows up as staged add the file to staging all right so get add and our SQL reference there we go the changes are now in staging commit your stage changes with the message all right so git commits Dash M and then feature add create table reference here we go cool check your git log again git log we added a documents yeah it's at the top pretty sure all right uh now you have four commits they're getting a little hard to see check the log again but this time you use one line all right get log dash dash one line and then it will all be on one line there we go or four lines for the four different commits all right that's better you get checkout to switch back to the main branch get to check out I mean there we go now we switch back to main but main doesn't have the uh the commit so we can do git log again with one line and then you'll see it only has three commits uh get lost Maggie of the dash dash one line there we go it only hits three you can see three commits on this branch and four on the feature Branch you're just on the commit and code you added on the feature Branch only exists over there for now a few of the branches you have to remind me the name of your other Branch all right to view the branches get a branch there we go you created the feature ad create table reference Branch made a commit and now it's ready to be added to the main branch you can use git merge Branch name to bring changes from a branch into your branch you're currently on Merchant changes from your future Branch into main branch all right so we can just do get merge or feature so merge feature add create table reference and then this will merge that Branch into our main branch that we're on and then we should be good to go the convincing code from your feature Branch we're added to this Branch there's a message with some info about the merge it's a fast forward merge uh check the log with one line flag again get to log dash dash one line there we go now that uh that commit is in there uh it was added to the branch with the merge you can delete a branch with get Branch Dash D all right get Branch Dash D and our Branch name so which is our add create table reference because we don't need it anymore since it's in Main so we can delete this Branch table reference reference here we go and I think we just delete it like that now there we go deleted Branch all right it said it was deleted above view your branches again yeah so it is definitely deleted uh you just left at the main branch I want to try it again last time you created a branch and then switch to it you can do both at the same time with Git checkout b or HD and create and switch to a new Branch name uh add drop table reference all right so git check out Dash B and then for each name is feature drop table here for reads here we go add a drop key to the table object of your Json file give it a value of how to drop a table all right so we can do a drop thing here drop and it's drop table drop table table name table name you click on that should be good and check your status get log or get status I mean get status all right that one was modified check the diff get diff and there's the changes Cube so I move on we have your changes to staging all right so git add SQL reference there we go commit your stage changes with the message uh feature add drop table reference all right so get commit Dash M feature add draft table reference there we go switch back to your main branch git check out mean so we can merge the changes all right um oh yeah I always do get Co for checkout because I have an alias on my computer but uh yeah I usually have to do the whole thing hit checkout mean all right remember that the code and commit you added aren't on this Branch so they disappear again view the branches on your repo so you can get the name of it to merge your feature into the main branch right get branch here's the name of our feature branch and then we can merge it sorry so git merge just for reference uh get merge feature add drop table reference there we go merged awesome commit from your feature branches added to main branch and we can safely delete our feature Branch all right so git uh Branch Dash D for delete and then we just type in feature add table reference again table reference there we go all right you're getting the hang of it the process is to create a branch make the changes you want commit them and then merge changes into your branch you started on pretty simple all right let's keep going create and check out our new Branch name feature ad column reference all right get checkout Dash B feature uh column references references there we go all right this Branch will be a work in progress add a column key to your Json object make an object like the other two give it a property add that has a value of altered table all right making objects give it a single property add a calm key to your Json objects all right so we're going to do a column column and then to add a column what do we have to do we have to do this thing right here which is Alter table call name yeah paste that and then we should be good to go all right view the diff to make sure and then your changes are what you expect get diff uh yep that's good all right add your changes to staging here's a tip you can use git add thumb to add all files to staging so yeah ninety percent of time you're going to use git at all or get add Dot and then be good to go all right commit your stage changes with the message feature add column reference I'm going to get commit Dash m feature add column reference there we go cool view your log with one line flag get log dash dash one line awesome click commit was added I see an error in the syntax of one of the commands you want to fix it but this branch is not for fixing it switch back to your main branch so you can create a new Branch to fix it okay I guess get uh check out uh Main remember that when you create a branch it will be a clone of whatever Branch you're on when you create it that's why you switch to main first create and switch to a branch named fix create table syntax uh git checkout dot dash B fix slash create table syntax the create table command is a function so it needs parentheses at the end I add those to end up and oh I see um the create table function oh I see this one does yeah this needs a parenthesis here all right cool uh check your status and dip to see your new changes all right get a status and check the diff get diff there we go there's our changes queue all right then add your files to staging get uh oh there we go cool commit your changes with the message fix create table syntax all right get commit Dash m fix create table syntax okay so now we have three branches open and I'll switch back to your mean so you can merge this important bug fix also yeah if I do get Branch we have three branches okay and then we can do git uh check out the main to go back to main view your branches to remind of the branch name there they are merger bug fix Branch into this Branch so we could do that with Git merge and then it's our fixed bridge so we'll go fix create table syntax syntax there we go be your log with one line flag get log dash dash one line there we go we create table syntax that's ahead uh the bug fixes in and you can safely delete the branch all right so we can go get Branch Dash D range Dash D um and then do it um fix create table syntax create table syntax there we go that bridge is now deleted your bug fixes merged into the main branch switch back to your feature Branch all right so get check out or I'm gonna I gotta see what branch I have it's quick okay branch and then yeah get checkout our feature Branch so feature add column references references there we go view your log with one live flag get log dash dash one line and that one commits with the the bug fix isn't in this Branch yet so I think we're gonna talk about that here uh you created this branch and made a commit since then admit for the bug fix was added to main this is common with with many people working on code base simultaneously yeah you need to update this Branch so it has the same commits from Main but you can't just merge that Branch into this one you need that bug fix commit to be in the same order here as it is on the on Main right after the drop table commit you need to rebase this Branch against Maine to do that enter get rebase mean to rebasis Branch yep I love get get rebase it's it's pretty awesome so we just do get rebase Main and then that change gets thrown into our file there was some fancy output there but you can see the parentheses from the bug fix commit uh were added to the table.create value which you don't need a log again all right and you can see that it was added here now um show me the log again all right get log dash dash one line all right there's add column reference we also have that create a table syntax or fix create table syntax this is right before head now all right the log show that the bug fix commit from Main was added and then commit from the branch was added on top of it now when this branch is ready to be merged in main it will have the same commit history you should try to keep your branches up to date like this by rebasing them often in your Json file add a drop key to the column object with reference for dropping a column all right so to drop a column we have to do something I also need a comma here all right so to drop a column we go drop column table name um or alter table column actually isn't it alter table call alter table table name table name drop column call name column name there we go okay yeah I forgot to pull on there that's fine okay cool check your status and diff to see the new changes get and then add them to staging I wonder if I can just add them to staging I'll do get diff um but then I'm just going to add them to staging get add-on here we go commit your changes with the message feature okay git uh commit Dash m feature add drop column reference all right view your log again make sure you use my favorite flag get to log dash dash one line there we go switch uh to your main branch get to check out mean there's another feature that needs to be worked on all right create and switch to a new Branch get checkout Dash B this time for a new branch and then add insert row reference reference there we go I pretend that this branch is for someone else working on a new feature at the same time you are working on the column commands add a row key to your Json object make it an object with an insert key whose value is this all right add a row for insert um add a row key oh yeah for a row I see so we can go row and then we have a insert statement and the answered statement is this thing right here insert into table name so let's paste that in that should be good uh yes awesome check your status and div and then add changes to staging so I'm just going to do get diff and there we see our row insert in there and then we can do git add all to add it create your changes with the message all right get commit Dash M feature add insert row reference and good to go awesome all right this branch is finished switch to your main branch so you can merge this commit in git check out Main here we are view your branches uh git branch there's our three branches merger Branch with the insert row reference okay so get language and then we're going to merge the feature insert row reference into uh this uh main branch I add insert row reference refer Ence there we go cool check your logs and make sure the commit was added then switch to your branch for adding column references all right check your logs gits log dash dash one line and then a switch to your branch for adding column references all right get checkout my Branch quick branch all right skits checkout our feature which is another column references column references roots another commit was added to main you should update this Branch again let's be more specific a rebase will rewind this Branch to where it last matched mean then add the commits from Main that aren't here after that it adds the commits you made to this branch on Top rebase This Branch against mean so it's up to date you should see a conflict all right we're going to rebase this against Maine all right so get rebase Main and we'll see a conflict yep all right the conflict arose because the first commit you added to this Branch changed in the same lines as the commit from Main so it tried to add commit but it couldn't because something was already there there are sections separated by characters um less than greater than equal that represents the commit you are on and then commit that is trying to be added uh this one which is okay and then fix the conflict by removing those um characters then making the Json object valid again all right so in here we can accept this current change except the incoming change or acceptable changes we also compare them uh generally I think if we uh accept both changes on this one um I don't know what they want though like just remove these for some reason and make them valid Json object skin okay we're going to accept both changes and then just fix this up a little bit manually um because it got confused with how to add this stuff all right so now we're good to go and check our status okay so get status here we are it says that you are still in the middle of rebasing there's one file that needs to be merged yet to add the file to staging like you would any other commits yep uh so yeah these are still changes this is so it's modified it's still like in the middle of this rebase um so we we have to add this to the staging again all right and then check our status again get status and now if that's in our staging and then we have to yeah we fix the conflicts and added them to staging it says all conflicts fixed run get rebase continue to continue to rebase yes so it says that right here make sure to run get rebase continue and we will do that right now get rebase dash dash continue and then it should work yeah awesome the last commit was added after you continue to the rebase without conflict the rebase is now finished view log with the one line plague get log dash dash one line here we are you can see the insert row row commit from Main was added to this Branch before the two commits you made here now this branch is up to date and you can continue working on it add a rename key to the column object um with this text in there all right so this is how you rename a column cuckoo uh rename and paste this in here awesome looks cool check your status and diff to see your new changes uh gits and then it's staging I'll just do get diff and get add all commit your changes get commit Dash m feature and rename column reference awesome there's now three commits that are unique to this Branch you will come back to it later switch to the branch we're adding new realm references all right switch to the branch for adding row references get Branch if I need to see what it is get checkout feature oh whoops I have to make sure to spell that out feature slash add insert row ref and this is a reference whoops there we go all right this branch is still up to date since no commits have been added to main since this Branch was created add an update key to the row object with this all right so we're going to copy this thing and add it is a update key for the key on the row yep right and you'll notice that the column stuff isn't in here at all and that's on our other Branch whoops there it is cuckoo check your status get status is modified now there's been a mistake this Branch was for the insert command not the update command um okay I see now you can put your changes aside would get stash stash your changes so you can add them to a different branch oh I see because it's named differently [Music] because it's insert row reference we could just change the name of the branch but we're saying we believe we're going to do it this way with good stash git stash is pretty cool though um it saves our changes but doesn't commit them all right you might have noticed your uncommitted changes disappear from file Checker status again get status um oops get status there it is all right so now uh it's nothing to commit working tree clean uh the changes you made are stash to view the things you have stashed with get stash list it's stash list there we go we have our work in progress uh you can see one item there bring the changes back with Git stash pop git stash pop and there we go now it's back the changes from the stash appear in file and get showed stats for you you're right where you left off before stashing the changes uh popping a stash like that will remove the most recent stash and apply it to your working Tree View the list of your stashes again git stash list and you see it's empty um let's change this back in your stash get stash there it is all right view the list of your stats changes get stash list again and now it's back in there uh the changes are stash again view a condensed version of the changes in the lace stash with get stash show get stash show okay cool you can see what file was changed and how many lines were added and removed from the file view the full changes with Git stash show Dash p show Dash p oh cool awesome awesome now you can see the actual changes that are stored in dash before you use the pop command to remove the lace stash and add it to your working tree you can add the latest stash while keeping it in the list with get stash apply buy your stash with this method all right git stash apply okay cool it showed you your status after applying the stash the one files unstaged again if you use stashless skit stash uh list still in there cool okay yeah the code from your stash was added to your working tree and the stash is still there in case you want to add it somewhere else uh stash the changes again okay it's stash um view the list get stash list I'm guessing there's two now yeah there is two now ah now now there's two things stash you can use the name at the front of each stash um stash at number uh with many of the stash bands select one other and then the least one the most recent stash is the one at top stash zero I'll view the condensed changes to the oldest stash with Git stash show against Dash show by putting the name of the stash after it which is stash at um index one yeah and it shows that stash instead of the first one uh next using a similar method show the full changes of oldest stash with the patch flag you used earlier all right so let's add a dash P there and then now it shows that stuff now there's two identical items in your stash drop one of them with get stash drop yeah or it gets stash drop and then stash name all right yeah because they're identical we might as well drop one no need for two of them view the list of SAS changes again to verify the one that got deleted uh it's stash list and there we see only one again it should just have one switch to your main branch so you can create a new Branch from that and add these changes to it get uh checkout oh main okay check out mean cool before I make you work on the wrong Branch again delete the branch for inserting row all right get branch insert row thing okay we want to delete that one okay get um Branch Dash D I thought we had something on there that we wanted to go off add insert row reference reference there we go create and check out a new Branch named add more row references okay get Branch Dash or I'm going to check out yeah check out get checkout Dash B for a new branch and then feature add more row references there we go show me your stash list again get stash list should still be there yep that's still there oh I see we're just taking your stash and we're putting it on this one that's uh that's pretty smart right there that is pretty smart all right so we're gonna do get stash pop and it will pop it on there awesome all right get showed you your status again and it looks like it recognizes the files new changes after adding the stash via the stash list to verify that's empty and also you'll see that that was that's added to this now um get stash list and now it's empty uh the list it's empty view the diff git diff and yeah you can see we update table name so that's cool uh it looks good add the changes to staging it uh add all sweet to your status get status um then commit this stage changes get commit m feature add update row reference reference there we go you work it along this branch is done for now switch to your main branch get checkout mean I'll merge your branch for adding row references that you just added to commit to all right so get orange and then our branch is forget so I have to do get Branch again get merge feature add more references add more row uh references there we go cool switch to your branch for the column references so you can continue working on that switch to our Branch for the column references um get check out our column references yeah feature add column references references cool all right once again commits have been added to main so you should update this Branch rebase this Branch against main to bring in the new commits you should get a conflict again all right git rebase mean and we get a conflict once again this conflict is a little trickier um is I guess a little bit yeah all right make the Json object tool again so you can add the changes and finish rebasing make sure you put all the references in their correct objects and in the same order they were originally in there may be a duplicate line you need to delete okay let's take a look at this quick so we have our current change and our incoming change our add column references is coming into this insert an update parting a row so the Row part is going on top and then our column stuff is on the bottom and we have an insert thing that's to go down here I think right oh no that's an extra yeah that's an extra one all right well we're going to accept both changes and then we're going to delete this one and I think that's pretty good actually I think that's good uh maybe not make sure you put all the references I need a hints these look like this yeah it does doesn't it add alter tables name what I think it does so I maybe I just need to run it oh there we go cool and we're 58 of the way through well wow we're cruising through this thing cruising are you the status of your repo each get status here we are you are still rebasing you fix the conflicts for the commit trying to be added looks like it was the Adcom commit that have conflict Adder changes to staging get to add all to the added to staging view the status again get status and it's going to say we need to get rebase continue yep continue to rebase get to rebase continue now the rest of your commits were added without conflict via your log with the on one line flag get log dash dash one line there we see all of our commits so beautiful so many of them all right it's the rebase added the row commits where they are supposed to be then the column commits from that this branch on top excellent now you can continue working on it kind of a reference to the calm object and then we have to add this um the key of primary key and value of this to the comma objects all right sir we're gonna add a primary key primary key I think like that I'm not sure paste that in and we'll see if that works primary key underscore actually cool there we go awesome all right check the diff get diff and we'll see our one line change our two line change because we added the comma at the end and it looks good all right um above it then add them to staging so get add all oops get add all right commit your stage files get commit Dash m uh feature add primary key reference reference awesome I forgot uh if you ever uh do that and you enter before uh the name a quote you can just end the quote on the next line so that's a cool little tip for you add foreign key to the column object for another command its value should be this all right so we need to add foreign key with this text under and foreign key here 4N 4 and key and then it's alter table name there we go let me check the diff git diff and then I'm guessing add it to staging you have to get at all and then commit them get commits Dash M feature add or Rin key reference reference that's the message there we go to your branch for the row references you can continue to work on those get branch and get checkout feature add more references add more row references so now we're going to work on this Branch for a little bit and you'll see that those changes for the uh for the column words in here at all so all right take a okay now we need to add a delete key because I'm taking guess of the value it should be delete from with the where okay so for the row we need to delete and then make sure there's a comma here and we can take a guess at what this is going to be I'm guessing it'll be delete from delete from table name from table name where the condition yeah I think that's how you do it great am I crazy am I Oh shoot what is it delete from it will need more condition leave from himalayanware condition what delete from okay run it oh row Dot delete.delete oh I need to get rid of that space Oh my gosh view the diff of your changes all right get diff there it is cool um Adam staging commit the changes get commit M feature add delete row reference here we go to the main branch so you can merge these commits git check out main um spell that out gosh darn it uh get checkout mean right where's the branch get merge and I gotta actually check see the branch quick and then get merge our feature which is add more row references add more row conferences references there we go all right you merge the branch and are all done with it delete the branch for the row references git Branch Dash D for deletes and then a feature add more row references there we go deleted I missed a bunch of the rename commands when I had you work on a few of the objects create and check out a branch named this all right get check out Dash B and I could check out Dash B fix add missing rename rename references there we go I forgot to add a command for how to rename a database in your Json file add a rename key to the database object the value should be this all right let's copy that add a renamed key to the database parts rename rename and paste this here alter database database rename all right view the diff of your changes get diff and then add them to staging that looks good to me and now I can add them okay add all and then commit your stage changes get to commit Dash M fix add missing rename database reference reference hey let's go all right leave this Branch for now switch back to your branch for the column references so you can hopefully finally finish it all right get um to get Branch get checkout feature add references right for a references there we go references so hard to type there was a commit to Maine since you last worked on this from when you merge the add more both references Branch Freebase this Branch against main so it's up to date and you can finish working on it rebases Branch against mean all right yes read git rebase mean all right add these changes in there and there's another conflict uh great all right fix conflicts Flex here they are let's take a look at this all right so it looks like this is a um repeat we can accept both changes and just remove that line and that looks good to me um yeah looks good to me all right cool all right do you fix conflicts check your status then add your files to staging get status status it's um add all right check your status again get status that's going to say continue um yeah get revised continue get rebase dash dash continue all right there was a conflict when it tried to add the first commit from the branch on top of the one that was brought in from Maine the rest of the commits were added without conflicts in your Json file add a unique key to the com object all right add a unique key to the column object and give it this all right to the column objects okay under here we're going to add unique unique and then paste this in here so table had unique column name view the diff diff there's our changes pretty cool pretty cool and then we gotta add them to staging cattle commit the stages uh files all right click commit Dash m and feature add unique reference reference awesome all right I'm going to show you a few ways to remove or undo commit the first is to Simply travel back in time it needs to get reset command to travel to any point in your commit history your current head is a reference to the last commit you just made use get reset head till they've won to go back one before head git reset head and until then one to go back one before head okay cool all right so now this is a mixed reset and I guess that unique part is still there though right um and it will put the changes from the commit you undid in your working tree you can see that it says there's unstaged changes oh I see so it just made it unstaged again so get um get status it's on stage it's modified okay that's cool view your log with one flying uh one line get log dash dash one line and there we see um it's not there anymore the unique and unique which was all right your commit for how to set up a phone to Unique is gone view the status get status there it is um view the diff get diff and yeah there's our diff again same as it was before and the changes from the resetter back in the working tree so when you reset to one commit before head it removed the most recent commit and put all the changes in the working tree if you use the dash dash hard flag with the reset the changes would not have been added to a working tree and if you use the soft flag the changes would have been added to the working tree and staging either changes back to staging so you can commit them again okay so git at all and then we want to commit them again with the same message I think I think that's the same message feature add unique reference yeah if we wanted to we could use a different message reverting is a good way to undo a commit because you don't lose the commit from the history you can revert the most recent commit with get revert head do that now all right so git revert head okay now we're in Nano or is this Vim so I think this is nano um uh get put you into Nano and is asking you uh to enter a commit message for the revert but they added a default one for you don't change anything in Nano just exit the file to use the default message we can exit the file with Ctrl X okay so control X to exit and it will keep this um I think revert um feature ad unique reference and then it will do that as well so Ctrl X all right view the log um with the flag get log dash dash one line and we can see yeah here's the command message they they did revert feature add unique reference all right using revert to undo that commit add another commit that is the exact opposite of it click a I see enter git show into the terminal to see the last commit added hit show yeah I could show Q okay uh type get show header layer one hit show head field A1 to take a look at the details of the original commit that you reverted okay I see uh if you look at the bottom of these two messages it shows the diff the diff of the revert commit is the exact opposite of the one before it effectively undoing the changes you've used rebase to update this Branch but you can enter an interactive mode to manipulate commits type git rebase interactive head Dash 2 into terminal to enter this mode and the head delete two means you will have a chance to change the last two commits okay so get rebase and we're going back in time with uh get rebase interactive so this is really useful and really uh really cool to do um it can be dangerous at times but you know how it is at the top of the Nano you can see the two commits with pick next to them yep um below them there's a list of options for working with them it means that it will use the commits as they are at the bottom it says D for drop or remove commit replace the word pick preceding your two commits with a d to drop them both when you're done save the file on exit Nano all right so we're gonna drop these we're going to drop both of these commands and we can use D to drop them both so just do D in front instead of pick on these and then we can exit um I think it's saved for us you must I would save the file with this control over right out and then we can exit our file name I think that's right file name um save the file and exit Nano but I wonder if did I say that right oh you can save and exit by pressing Ctrl X then Y and then enter oh whoops um let's cancel C so I just do control X then y then enter and Y oh and then enter okay go okay view your log use the one line flag get log dot dash one line and we can see that those that reverts commit is not there anymore okay both the commits you add the unique command and the one to revert it were dropped enter another interactive rebase that goes back to the root instead of head two I'm going to show you how to change complement message all right next Dash root means that the rebase will go back to your very first commit oh wow okay it's gonna show a lot of them then all right git um rebase dash dash Interactive and then dash dash root um to go back to the root instead of head two again so there's all of our picks uh you can see that the latest commit is at the bottom here be careful not to change the wrong commits one of the options is R for reword um okay so use the commit but added the commit message replace pick with an R next to the commit message with feature Adcom reference feature ad column reference featured added column reference um is that down here yeah there is and we have to do an R to reward it okay R and then um reword the message it's the very first commit you added to this Branch when you're done say to file X and Nano it will put you into another Nano instance to reword the commit message don't change anything in it yet oh I did not know that okay that's kind of weird Okay so let's say the file so Ctrl X Y enter and then we're going to change the commit message in this one all right so we need to edit your commit message and S at the end of the commit message so it's feature Adcom references I see we just forgot an S there now when you're done save the file and exit Nano so control x uh yes so Y and then enter okay view your log get dash dash get logged online there we go and that's thing should be changed now git add calm references yeah feature ad column references is cool now okay I thought it was row message okay whatever row references add row of references I don't know whatever the message was rewarded but there's a problem look at the commit hash for your initial commits from the last two times you viewed the log it's that string left right here is the hash um there aren't the same ones uh they aren't the same ones anymore since you rebase back to the root the same goes for the rest of your commits when you rebase indirectly it changes all those hashes so it sees them as different commits if you were to try and merge this into main it wouldn't work because they don't share the same history anymore for this reason you don't want to do an interactive rebase where you go back past commits unique to the branch you are on fortunately you can fix this enter get rebase main to realign the history of the two branches okay I get to rebase Main okay interesting so that's how you fix it okay view your log again use online click get to log online the Q now the hashes are the same as they were before you rebase back to root which is what they are on Main enter another indirect rebase go back to the first commit you added to this Branch it's head five okay so git rebase Dash I is short for interactive I'm pretty sure and then we can just go ahead until day five to go back to that one all right squash and commits means that you will take a bunch of commits and turn them into one this is helpful to keep your commit history clean and something you want to try to do replace pick with an s next to all of your commits except the one with the message add column references Okay cool so we're going to change all these picks to s's for squash so it means they're going to get squashed into that add com references commits and then it will clean it up when you're done save an exit file so Ctrl X yes and enter Nano brought up a list of all the commit messages you use for the commits don't change anything in there just exit the file to use those messages and finish squashing the commits All rights don't change anything in there just exit the file so Ctrl X awesome all right view your log with the online flag get log dash dash one line awesome and now all the column commits you made to this branch have been squashed into just one commit at the very top view the log again but use minus one instead of one line to view only the last commit so get to log um dash one all right so it added these stuff to its that's kind of cool um you can see that your one commit has all the messages that were in Nano which are all of the commits you made to this Branch squashed into one commit I think you are finally done with this Branch go to your main branch so it can get merged if I get checkout check out Main and then we're going to merge it in so merge it so git merge um I forgot the branch name what's the branch name get merge our add column references right yeah uh feature add column references awesome seven is your sentence seven insertions hopefully there are no conflicts delete your branch for adding information about calm cleaning since you're done with it all right get Branch Dash D feature add column references all done with that one go to your branch for adding up on my end set we're missing there's one we were to add gits um Branch go to your branch git checkout fix adder sing rename references um there there was added submit to main since you last worked on this update this Branch with a rebase against main okay get rebase dash dash uh get rebase mean I mean all right it worked awesomely all right you viewed the most recent log with dash one you can view the last X number of commits with any number instead of one it'd be the last five commits um with the one line flake right so git log Dash 5 and then dash dash will line here we go all right this branch is up to date now and your Json file add a rename key to the table objects all right let's add a renamed key to the table object the value in is in the hints but just give it a try first okay rename to table rename the table okay how do we rename a table that is the question hmm um alter table table name table name rename to new name I'm guessing that's what it is not entirely sure nope um rename two rename two new name let's try that a let's go all right check the diff of your changes get diff awesome that's what we want I'll add them to staging get at all submit your stage changes get to commit Dash M fix add missing rename table reference awesome view your last log files I think I have that here it is awesome all right you have two commits on this branch that could be squashed enter an interactive rebase that goes back on the two commits and squash them all right get rebase Dash I head um tilt A2 all right so we want to replace pick with s next to your commit for adding the rename table reference um be careful not to do the wrong one okay with s next to your commit for adding the rename table reference rename table reference so we just want to do s on the second one okay and then when you're done save an exit Nano all right control X yes and enter aha the lines that don't start with a hashtag will be the commit messages add a new message at the top of the file on its own line I'll give it the text fix add missing rename references all right so we can do enter and then fix add let me sing rename references reference is like so when you're done saving X of the file all right so Ctrl X and yes and enter huh let's go view only the last commit in your log to see your squash commits gets log-1 okay there's our squash commits I think this branch is ready to go switch to main so we can merge it get uh checkout Main and we are going to merge this sorry to get launch um yeah merge fix CAD missing rename references references there we are listen review branches get branch we just have those two delete all your branches because I mean get to Branch Dash B fix add missing missing rename references and that should delete it awesome I think the file is complete thanks for making this for me view the log with one line flag um get log dash dash one line here's all of our commits awesome all right that's a nice looking commit history there's one more thing you should learn create and check out a branch name feature ad git ignore all right yeah we're gonna get ignore cool okay so get check out ignore all right use the touch command to create a file name.env touch dot EnV right this is where we put our environment variables aha for running code oftentimes there may be sensitive information in it like passwords and stuff all right add the text secret my secret to the file all right so we can do that with a go so that's kind of cool Echo Secret s equals I Secret s and then that goes into EnV a let's go view your status um get status and you can see that it is waiting it's on tracked uh you can see that you can be files new use Touch again to create another file name to dot get ignore touch that it ignore all right view the status again get status it's going to be the same thing let me actually also have Kit ignore in there um add the text Dot in V2 your git ignore file and then it will ignore the EV file it's pretty cool all right so we can just do Echo dot EnV into our DOT get ignore gitig or there we go and now when I do git status again EnV is gone yeah let's go now the EnV file is being ignored by git because you added it to the getting your file there are often a number of things you don't want to include in a repo especially if it's publicly visible now you know how to keep them from being tracked by git add your new changes to staging do I get at all commit your changes with feature ad gig more get um submit Dash m feature add plot get big use Touch create another file named Sample EnV All Right Touch sample dot EnV and then view the status get status right it won't ignore this file sensitive information can be stored in the EnV file but people need to know the variables that are in there so they can run a repository locally add secret equals to sample Envy all right so we're gonna go secrets equals and that's going to go into the sample.ed sample .ed let's go now when someone wants to run your repo they will know that they need to create EnV file and add a value in it for secret grab your new file to staging get add all and then add a commit message get commit Dash M feature add sample.env there we are how far are we we're so close 95 percent uh view the last five commits in your log with one line flag all right get um get log Dash five dash dash one line there they are the two commits you made to this Branch can be squashed do an interactive remiss that goes back to all the commits unique to the branch all right so get a rebase dash I head till they too and then we're going to squash the second one I'm guessing squash the sampling V yeah all right so that should be an S and then save the file so Ctrl X I enter add a new message at the very top of the file degrees is going to be a feature to add dot get ignore and sample EnV EnV all right when you're done save an exit file all right so control X Y enter hey view only the last commit in your log get log-1 switch back to main git checkout to Main check out Main and then merge a branch all right so git merge feature add git ignore feature add forget ignore uh Delete the feature Branch you just merged all right so get um delete or get Branch Dash D Ranch Dash D feature add get ignore there we are deleting that Branch I think it's all finished you're logged with the one line flag to see your whole history it's log dash dash online and there's a whole history um we started at the bottom now we hear initial commit and add a bunch of stuff and make sure to also add the get ignore and sampling V alright so all right looks great view the log one last time without any Flags gets long and we'll see all the details of all these commits as well and what happened in them okay congratulations you are finished with your repo for now tutorial completes all right let's go so now I'm gonna go to free code cam it should be checked off let's see here uh learn gits and it is checked off awesome next thing we're doing is the periodic table database and it's a project and we're going to use bash looks like to get information about chemical elements from periodic table database so looking forward to that and I will see you later make sure to like um subscribe and comment and yeah thanks for watching bye