Part 2-Git And Github Series- Git Merge,Push, Checkout And Log With Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so guys we're going to continue the series of tutorial with respect to git and github in our previous video we have seen uh how to install git cli and then we did it for windows you can similarly do it from mac or linux and then we did uh the global configuration setup with your username and email address that we did it you can also use some color ui if you really want to use to see that how the untracked files will probably look or modify files basically look you know they'll just add some coloring theme so that you can actually clearly see in the command prompt then um we did get in it we also tried to see how to clone a url and now we are going to with respect to git status also we checked it out we also saw how to add files for your next coming basically in the staging part uh now you're going to see some commands like get reset get difference get different staged and obviously we have also seen commit and all right along with this if you just follow this entire chat along with that you'll be able to understand everything okay so after that we'll also see some branching strategies because see in a team many people will be working many developers will be working and whenever a story is assigned to you right what you will actually do is that you will take a main branch and you'll probably create a new branch from that and that branch will be having the copy of the main uh the main branch itself because all the code will be actually present over there then you do the coding then you commit it into that particular branch and you merge that branch with that specific main branch right so all those things will try to do it now now this was my command prompt right now you can see that i if i go and write git status so what does get status basically do is that it shows modified files right now i don't have any modified files right over here so i'll go to this folder i will create a new document okay and once i create it here you will be able to see get status and obviously in this particular status you can see that there is one untracked file which is called as new document three dot txt right so over here to make to make it sure that we are tracking this we really need to use what command that is nothing but get add command right get add file so here you can see add a file as it looks now to your next commit so that basically means we are basically moving it to the staging so that is the reason why we have to basically use get ad so here i'm going to use git add i'm not going to give the file name again and again i'll just use dot because i just have only one file over there dot dot will make sure that all the files are basically getting added now i'll clear the screen and probably now go ahead and see get status obviously one file i can actually see over here okay now let's see what is get reset okay here one more option that you have is something called as get restore okay so if i write git restore and if i write minus minus staged uh and the file name so the file name is new new new text document and that file name is three now if i enter this this is going to unstage this okay so let's see now if i go and see get status here you will be able to see now it is an untracked files okay so this is what you can basically use gets restore uh minus minus stage with the file name one more way is that you can directly use reset also so here i'm just going to clear clear my screen or let me just add get add the file name uh and then i'm going to clear the screen now if i probably see get status right here you'll be able to see that all the files uh this particular file has been tracked and it has been committed to the staging environment right still uh you can say that this needs to be committed to the staging all right that's this entire commits uh you can just say that okay we have done one step ahead and now we are going to move this into staging okay now let's see there is also one thing called as git reset so if i probably write great reset along with my file name right so i can also use file name over here you can see this file right so file name basically means here i'll be using new text document three dot txt right so this is my new file name so if i do this reset and now if i probably see the git status so it will do the almost the same task what we did with the restore okay so i hope everybody has understood about what is reset okay now let me do one thing let me add this file again okay and then if i probably do get status here you will be able to see that okay fine this changes to be committed are there and this is the file that i really want to move it to the staging part right now now there is also something called as get diff and get if staged okay now see what i what will happen if i write get if staged okay so this basically will show me like if you probably see the description description a difference of what is changed but not staged right right now the real staging will only happen when this added file will be committed to that particular staging environment right so how do we do that for that we basically have to write git commit minus m along with some message right when i do this then what will happen this particular new file you will be able to see it will be moved to the staging environment now right now we are just seeing what is the differences that is there and what is the file that i just added but not committed to the stage so that is what you see over here now finally what i will do is that if i am sure about this particular commit i will move this file to my staging environment so that it can be pushed to the git repo github repository so here i'm going to write git commit minus m so let's say this is my new document commit okay i'm just going to give some message and i'll press enter okay now if i clear the screen and if i execute the same thing here now you will be able to see nothing is there right that basically means everything is moved to the staging environment which is basically my my current local staging environment i already told you that it is just like a playground whichever needs to be committed to the main repository first of all i'll push it over there and then i'll then sorry i'll first of all commit it over there and then push it to the github main repository right now if i also see get status nothing is there your branch is ahead of origin main by one commit that basically means it is good now checking the main branch over there and it is saying that okay you are just ahead in your local repository by one commit now i'm going to push this entire commit over there so in order to do that i'll write get push origin to the uh main branch right because that is the main branch so once i execute this now if i probably go and see over here one more file called as new text document three will get created okay so here you can see and this was the recent commit that we did with respect to this all the changes this was the new file that got added i did not write anything in the file but that is fine okay now again go let's go back we have completed all these things now this was regarding stage and snapshot stage and snapshot basically means that after we commit right something like when we write this particular command which is like get commit right get commit this is basically going to take a commit snapshot put it into the staging part and that staging part that entire package will be moved towards the main github repository okay now let's go ahead and understand about the branching strategy okay so branch and merge first of all if you if i just go and execute get branch okay so here you can basically see that i have a main branch what if i want to create a new branch in my local repository now in order to create a new branch in my local repository i'll go over here i just have to write git branch branch name now why this is specifically used now understand let's say that i have been assigned a new story to work with right so what i'll do is that first of all my entire code repository is in the main branch so i'll take a copy of it while taking a copy of it i'm just going to cut a branch from that okay so from the main branch i'll just cut a branch now here you can see this if i write get branch branch name let's say this will be my developer branch name and if i execute it now if i probably see what is the get branch that i am working in now we are basically working in main branch right but i have actually created a developer branch now if i want to move and move to the developer branch and work in this developer branch so what i can do i can basically write get checkout and here i will basically go to my developer branch so here you can see that it is switched to the developer branch now if i probably see get branch here you'll be able to see that i'm in the developer branch now this is fine okay now whatever work you do over here whatever commit you do over here it will basically go to the developer branch okay so what i'm going to do i'll again go and create a new text document now my new text document is created now what i'm actually going to do i'll go to write kit status here you can see that on the branch developer it has the main copy of the main branch right and obviously all the files will also be here but now i have created a new file now i have to make sure that this file gets added into the branch developer right developer branch in short so here i'm going to again do git add and then i will be saying get commit minus m so that i move this commit snapshot to the staging environment so let's say this is the new story i am working as a developer okay i'm just writing my comment okay please don't worry about the spelling and all uh okay so i'll execute it now what will happen this entire changes will be going to the developer branch right so if i probably go and see the git status now it is basically in the developer staging environment now let's go ahead now this we have already learned if you say git checkout with that specific branch name you'll be able to get a check out okay now this is super important get merged let's say that my work is done now i want to merge this entire commit to my main branch in the local repository itself right so what i'm actually going to do so i will say first of all i will check out to the main branch okay so right now if you go and see get branch okay so here you'll be able to see i'm in the main branch okay now what i'm actually going to do i'm going to say git merge with this specific branch so it says that merge the specified branch history into the current one so i will write git merge with my branch name called as developer so once i execute this you can see the new text document found one file change this this is there now if i probably go and see the git status here you will be able to see that your branch is ahead of origin main by one commit now what you can do you can also make sure that you write git push okay get push uh from origin to main so once i execute this now this new file will be pushed to the main branch now if i go over here and probably see in git tutorials you'll also be able to see the fourth file and this are all my commits that i have actually done this is the new story i was working as a developer okay this is super super easy but uh there is one more thing that we need to find out and probably we have also collected this right git merge branch now we'll also understand about git logs now what will get log basically say okay let me clean the screen if i write git log here you'll be able to see all the commits from the previous logs that we have done this is my second commit third commit formal commit i think the latest five commits it will be able to say so i'll just press q from there now what i'm going to write i'll say get log minus p let's say i want just my the last three commit so here i will be using minus p minus three minus three will just save you the last three commits so this is the new document commit here you can say this is the new story i'm working so all the information of the commits also you'll be able to see from the logs now whenever you get this scenario just press q you will be able to come out okay so yes in this video we have committed we have i mean we have i have explained you about all these things differences stage commit this this this okay merge branch and all okay now uh what we are also going to do with respect to this whenever we create a new branch right we also need to make sure that we commit that entire or we push that entire code from that branch to our main repository okay and that i will try to show you in the next video and we also going to see all these things because once we commit from our our local repository to our branches in the main repository let's say that over here i i've created a branch and then from that particular branch i've done the coding and i pushed that entire code to that specific branch code in the github main repository because right now i just have one branch only right i don't have two branches but it is always a good idea that i should be able to push as an another branch and later on we can pull we can do a pull request and we can merge this both the branches also so that is what we are going to see in the next video and apart from that we are also going to see all these things all these steps which will be super important so yes uh this was it from for this particular video uh in short we have spoken about stage and snapshot and then we have also spoken about branch and merge so in the next video we are going to continue the discussion with respect to this so yes i'll see you in the next video thank you
Info
Channel: Krish Naik
Views: 12,991
Rating: undefined out of 5
Keywords: yt:cc=on, git branch, git checkout, git log, git merge branch, git commit, git push, krish naiuk git and github tutorials
Id: SMqxisMGfYM
Channel Id: undefined
Length: 13min 9sec (789 seconds)
Published: Sun Jul 24 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.