Transcription
[Music] hello everyone. I'm Landon schlong, and today we are going to learn git by building a SQL reference object. 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 read me.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.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 -m feature add drop column reference`. All right, view your log again. Make sure you use my favorite flag. `git log --oneline`. There we go.
Switch uh to your main branch. `git checkout main`. There's another feature that needs to be worked on. All right, create and switch to a new branch. `git checkout -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 an 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 `git 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, `git commit -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 checkout Main`. Here we are. View your branches. Uh, `git branch`. There's our three branches. Merge branch with the insert row reference. Okay, so `git language`, and then we're going to merge the `feature insert row reference` into uh this uh main branch. I add `insert row reference reference`. 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. `git log --oneline`, and then a switch to your branch for adding column references. All right, `git 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 main, 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 main so it's up to date. You should see a conflict. All right, we're going to rebase this against main. All right, so `git 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 `< > =` 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, accept 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 `git 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. `git 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 `git rebase continue` to continue to rebase. Yes, so it says that right here. Make sure to run `git rebase continue`, and we will do that right now. `git rebase --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. `git log --oneline`. 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 `git diff` and `git add all`. Commit your changes. `git commit -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. `git Branch` if I need to see what it is. `git checkout feature`. Oh, whoops, I have to make sure to spell that out. `feature/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 an 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. `git 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 `git 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. Check status again. `git status`. Um, oops, `git status`. There it is. All right, so now uh it's nothing to commit, working tree clean. The changes you made are stashed. To view the things you have stashed with `git 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 `git 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. `git stash`. There it is. All right, view the list of your stats changes. `git stash list` again, and now it's back in there. Uh, the changes are stashed again. View a condensed version of the changes in the lace stash with `git stash show`. `git 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 -p`. `show -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 `git 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`, `git 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. Stash the changes again. Okay, it's stash. Um, view the list. `git stash list`. I'm guessing there's two now. Yeah, there is two now. Ah, now now there's two things stashed. 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 `-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 `-P` there, and then now it shows that stuff. Now there's two identical items in your stash. Drop one of them with `git 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. `git uh checkout oh main`. Okay, `checkout mean`. Cool. Before I make you work on the wrong branch again, delete the branch for inserting row. All right, `git branch insert row thing`. Okay, we want to delete that one. Okay, `git um branch -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, `git branch -or`. I'm going to check out yeah, `checkout`. `git checkout -b` for a new branch and then `feature add more row references`. There we go. Show me your stash list again. `git 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 `git stash pop`, and it will pop it on there. Awesome. All right, `git 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, `git 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. `git status`. Um, then commit this stage changes. `git 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. `git checkout mean`. I'll merge your branch for adding row references that you just added to commit to. All right, so `git orange`, and then our branch is forget. So I have to do `git Branch` again. `git 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, `git 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 and 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 `git 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. `git add all` to the added to staging. View the status again. `git status`, and it's going to say we need to `git rebase continue`. Yep. Continue to rebase. `git rebase continue`. Now the rest of your commits were added without conflict. Via your log with the on one-line flag. `git log --oneline`. 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_`. Actually, cool. There we go. Awesome. All right, check the diff. `git 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 `git add all`. Oops, `git add all`. Right, commit your stage files. `git commit -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 -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. `git branch`, and `git 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.delete.delete`. Oh, I need to get rid of that space. Oh my gosh. View the diff of your changes. All right, `git diff`. There it is. Cool. Um, Adam staging. Commit the changes. `git 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, `git checkout mean`. Right, where's the branch? `git merge`, and I gotta actually check see the branch quick, and then `git 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 -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, `git check out -b`, and I could `check out -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. `git 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. `git commit -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, `git um to git branch`. `git checkout feature add references right for a references`. There we go. References. So hard to type. There was a commit to main 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. `git status`. Status. It's um `add all`. Right, check your status again. `git status`. That's going to say continue. Um, yeah, `git revised continue`. `git rebase --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 main. 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 -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 a 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 `git reset HEAD~` 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 `git`, um, `git status`. It's on stage, it's modified. Okay, that's cool. View your log with one flying, uh, one line: `git log --oneline`. 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: `git status`. There it is. Um, view the diff: `git 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 `--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 add .`, 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 `git 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, `git` 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 add unique reference`, and then it will do that as well. So Ctrl X. All right, view the log, um, with the flag `git log --oneline`, 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 `git show HEAD~1`. Hit `show HEAD~1` 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 -i HEAD~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 `git rebase` and we're going back in time with, uh, `git rebase -i`. 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: `git log . --oneline`. 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 2. I'm going to show you how to change complement message. All right. `HEAD~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 --interactive` and then `--root`, um, to go back to the root instead of HEAD 2 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 add column reference`. `feature add 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 add column 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: `git -- --git log --oneline`. There we go, and that's thing should be changed now. `git add column references`. Yeah, `feature add 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 `git rebase main` to realign the history of the two branches. Okay, `git rebase main`. Okay, interesting. So that's how you fix it. Okay, view your log again. Use online. Click `git log --oneline`. 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 5. Okay, so `git rebase -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: `git log --oneline`. 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 `-1` instead of `one line` to view only the last commit. So `git log -1`. 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 `git 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? `git 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, `git branch -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, `git rebase --`, uh, `git rebase main`. I mean all right. It worked awesomely. All right. You viewed the most recent log with `-1`. 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 -5 --oneline`. 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. 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. `rename to rename to new name`. Let's try that. A. Let's go. All right, check the diff of your changes: `git diff`. Awesome. That's what we want. I'll add them to staging: `git add .`. Submit your stage changes: `git commit -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, `git rebase -i HEAD~2`. 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: `git log -1`. Okay, there's our squash commits. I think this branch is ready to go. Switch to main so we can merge it. `git`, uh, `checkout Main`. And we are going to merge this, sorry, to `git launch`, um, yeah, `merge fix add missing rename references`. References. There we are. Listen review branches: `git branch`. We just have those two. Delete all your branches because I mean `git branch -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, `git log --oneline`. 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 add .gitignore`. All right, yeah, we're gonna `.gitignore`. Cool. Okay, so `git checkout ignore`. All right. Use the `touch` command to create a file name `.env`. `touch .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=mysecret` to the file. All right, so we can do that with a go, so that's kind of cool. `echo secret=mysecret > .env`. A. Let's go. View your status, um, `git 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 `.gitignore`. `touch .gitignore`. All right, view the status again: `git status`. It's going to be the same thing. Let me actually also have `.gitignore` in there. Um, add the text `.env` to your `.gitignore` file, and then it will ignore the `.env` file. It's pretty cool. All right, so we can just do `echo .env > .gitignore`. `.gitignore`. 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 `.gitignore` 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. Add your new changes to staging: `git add .`. Commit your changes with `feature add .gitignore`: `git`, um, `commit -m "feature add .gitignore"`. Use `touch` to create another file named `sample.env`. All right, `touch sample.env`. And then view the status: `git 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=sample.env`. All right, so we're gonna go `secret=` and that's going to go into the `sample.env`. `sample.env`. 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: `git add .`. And then add a commit message: `git commit -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, `git`, um, `git log -5 --oneline`. There they are. The two commits you made to this branch can be squashed. Do an interactive rebase that goes back to all the commits unique to the branch. All right, so `git rebase -i HEAD~2`. And then we're going to squash the second one. I'm guessing squash the `sample.env`. 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 `.gitignore` 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: `git log -1`. Switch back to main: `git checkout to Main`. Checkout Main, and then merge a branch. All right, so `git merge feature add .gitignore`. `feature add .gitignore`. Uh, delete the feature branch you just merged. All right, so `git`, um, delete or `git branch -D branch -D feature add .gitignore`. 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: `git log --oneline`. 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 `.gitignore` and `sample.env`. Alright, so all right. Looks great. View the log one last time without any flags: `git log`. 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 camp. It should be checked off. Let's see here, uh, learn Git, 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.