 Yeah, and one more thing, since we have Wi-Fi issues, so I request to let's use your own hotspot, connect your laptop to your own hotspot. We will be doing, we'll be pushing the code and things, stuff like that. So please have it connected so that we can have continuous learning. Good? Okay. All right, so with the basics beginning, start. Why are we here? You learn Git, why? It's most widely used, but why do we need? What is source code? Management, version control, I heard something like that. What are those jargons? If I have to explain this to some kid, if I tell that version control, would you understand? Okay, so basically, we are coming to the point to understand why actually something like Git we need. So for example, let's take an example. So Git actually helps you to make mistakes, but still fix them. Git actually protects you from yourself and others. How? Let's see it. So for example, imagine I'm in a fantasy world and I'm in a blogger. I'm a blogger and I'm just first, I'm making a draft of a blog, let's say. So I say, okay, hi, this is Pooja at three, two p.m. here. Now what happens? I want to save it, second step. And I save it into some file. Let's say my blog dropped one. Now I realize that, okay, I made a mistake. The P, it should be capital, I go again. Is it visible till end? So I want to go in again, change it and I again save it, okay? And while doing this, I made a mistake. Instead, mistakenly I made it 3 p.m. Now I want to go back and go to the previous position. What would I do? Control Z, yeah, we are well versed it. But what if I had closed this file? I had closed this file. Would I still be able to go back to the previous situation? No, it means I somehow want version of my current file and version of my previous file. Isn't it? That's where we go. That's where we call version control. I want to be able to control my current version of file, previous version of file and all the previous versions. That's where we are going to learn something like Git which helps us maintaining this. So let's go now and understand what actually Git does apart from working with your versions. So Git basically protects, this is just the basics to understand. Git basically protects you from yourself so that any mistake you do, you can go back and Git also tells you to collaborate with your team. Let's say, being a blogger, I want to take reviews from my friends and they also want to make comments on it. So they do not mess up my code. My code is in my blog basically. So I want people to collaborate easily. Okay, I want to go out to go office and I'm not working on blog anymore right now. I want to stop writing and I still want to go back, right? So I can do multiple things, saving my history and come back to work. I can collaborate with others and basically I can work with others without pulling their hairs. Oh, why did you remove my code? Why did you remove my blog? That is why we are going to learn Git. Now let's see how actually Git works. So this is a real world situation. So suppose Pooja is a blogger and she's writing a blog, right? And she has now passed on a draft of this blog to some of her friends. And those friends are also going to now make amends to this blog. So suppose somebody notices a spelling mistake or somebody notices something you have missed, right? So all of those people are going to make changes to the same draft, right? And now there can be issues in synchronizing it. Somebody may undo something that somebody else did and somebody may add something which you don't want, right? So to take care of this, there has to be some kind of a system in the center which takes care of synchronizing all these edits. So that system is called Git, basically. So you version your files and then there's a system which allows you to make all these amends in a safe manner. We all did. So I'm just skipping. We all have installed. At the next step, we are going to start working on this. I want you to go to everybody to this page. This page, github.com slash. It's in your sheet you got P000J4 slash. Git workshop, Git underscore workshop. So let's go to the page. The instructions are on your page, the helper page. Make sure everyone is logged in with their own GitHub accounts. You can just simply sign up with your email ID. If you have any questions, please raise your hand and I'll bring the mic over to you. So let's just go ahead and click it. We'll explain you what this fork is and what we are actually doing here. Is it audible now? Please raise your hand, like in a table once or some only. Yeah, it's there on the page. It's limited time. Everybody's there and you click the fork button and it creates something. It takes you to some page where your name is mentioned in the left slash Git workshop. So you should see your account here like she's seeing hers. You should see your own GitHub account. So just click on your GitHub account and it should create a copy of this GitHub repository for you into your GitHub account. So forking is nothing but taking a copy of any other GitHub repository. So it's very similar to how you do control C control V on a window system. You just choose a folder and you create a copy of it. I can explain. Forking is nothing but it just made a copy of my repository under your own name. Now you can start and work on it. So we're going to start working from here. We're going to talk less and work more. So just pay attention to what we're doing and then you need to replay there. And wherever you feel that you are stuck in, you need help, just raise your hand. One of our volunteers will reach you. All right? So we did forking and now we're going to understand what we did actually. So we are talking about gate, but we opened a github.com. So we're going to understand what these three things are. Gate versus GitHub versus GitHub repository. So this is actually very critical to understand the difference between Git and GitHub, right? A lot of people confuse Git with GitHub, right? So let's begin with understanding what a Git repository is. So a Git repository is nothing but the folder. The folder into which you are saving all your files, all your code. That is called a GitHub, a Git repository, right? So a Git repository is a folder which can be stored anywhere. So it can be on your local machine. It can be on a cloud server. It can be with the github.com server, right? So what is Git now? So Git is just a program which allows you to interact with your folder. Whatever changes you are making to the folder, Git is the system that can track those changes, right? So when you are using various Git commands, you tell what kind of changes you are making and how those changes should be propagated everywhere. And now what is GitHub? So GitHub is nothing but a cloud repository provider. So github.com is one of the providers. Similarly, we have something called Bitbucket. We have something called Git Labs. There are so many different Git repository providers, right? So GitHub is the most prevalent one which everybody might be acquainted with. So it's just nothing but take a backup of your folder. Whatever you're working on in your local, you can just sync your local with the github server. So basically when you still be safe with your code, it creates a copy of your code into cloud. Yeah, so we are going to start now and we're going to do first step is we cloned it, right? So go to your page again and we see a clone button in the right side here. Everybody sees? Click clone, be in HTTPS mode only. Copy this link. Yeah, yeah, copy this link and for Windows, open your command prompt or for Linux or Mac, open your terminal. Go to your terminal. Just go to somewhere where you want your folder to be. You can go into documents, into desktop. Wherever you want your folder to be copied from GitHub. Copy the link and we need to actually work on this from the batch basically. So just make sure when you are doing git clone, you have your username here. So don't copy the pwoj4 link that you had, but instead whatever you got after forking. So git clone is nothing but a command which brings the github whatever you forked into your own account, right? So you created a folder with a file called readme.md. So once you git clone, that file is going to come into your laptop. So with git clone, just make sure that this particular user that you're seeing here, you have your own github username. So fork is nothing but whatever we are doing with git clone to happen from github to your laptop, fork is github's way of doing it within github. So it is taking somebody's folder and copying into your account. You can use this also, like you can use from now. Git clone and... It's just a dummy file we added because git does not allow you to have a blank repository basically. So first time you need to add at least one file for you, it git to begin showing you. No, it's not relevant, you can just skip that file. So we'll be creating new files as we go ahead. So if you already have existing github repository to which you have access, you can directly clone it as well. Yeah, git provides the command to clone, but you need to run that command into your terminal. All right, so we all have cloned and we have something. So with clone, what we're doing is we are telling github to bring that copy to my own machine so that I can start working on. So clone, like Neem says, clone the existing one. So that's why it's a simple git clone. So we all have the local copy in our machine. So after finishing the clone, you must see a folder called git underscore workshop in the same path. So just cd into that folder. So we are, therefore the sheet, whenever you get confused, so we are going to do going to go in that path, cd. So right now I'm, so you might have. So you would see something like this on your laptop. You would have got a folder called git workshop. So you just need to cd into this folder. Yeah. So for the instructions, because it depends on your laptop, if you're in Windows, the path will be different. So for me, the path was different. So I suggest you prefer to create a directory called seconc and then put it there, everybody. In case you feel a lagging behind, I would suggest to pair up with other people to understand how they are doing. So what we are going to do is now we are going to add our first file. So since we thought in the fantasy world we were a blogger, but sadly we are a developer. So we come back and start coding. So what we are going to do is we are going to create a first file. So the very first thing which we are going to do is we are going to introduce ourselves to git, basically. We are going to tell, hey git, understand me as my user. So we are going to type this command in the command line, say git config, we'll get the PPTN videos later. Let's do the real time here now. The git config is nothing but git's way of knowing you. So we talk that git is a tracking system which knows who did what at what time, right? So the who part is what we are telling git here that this is me. My name is this and this is my email ID. So just say git config, user.name, your user name, and git config, user.email, your email ID. Done? Let's make it interactive. Any table is done, say, hands up. They're just telling, add my config from now on understand me as my name and my email ID. Simple. Done? Shall we go ahead? Things which we are going to cover, but let's not try to read all of them. We are going to use all of them one by one. Go to your command line. Once you're inside the folder, so the git context is already enabled. So any git command you run inside your folder, git will be able to recognize it as a git command, right? So, yeah. So let's begin by seeing what is already there in the folder. So we have something called a readme.md. It's just a dummy file that we added to begin with, right? So you can simply ignore this file. So let's get acquainted with a few git commands to understand what we already have. So if you do ls minus la, you should be able to see something called a .git folder. For Windows system, please figure out the command. So there must be a command to show hidden files. Same command, okay. So this .git is the metadata that git is tracking for you. So there's one important file here that we should be looking at. So it's called .git slash config, right? So whatever you did as part of git config, we gave a global flag. So that is saved in the global git, but this particular file tracks what you are doing into your local system. So this particular file says that your remote origin is this particular path from where you cloned the git repository, right? And we have, you can ignore the second remote. So we already, I have added a different one. So if you, this is how git knows that which remote GitHub repository should this particular folder sync to, right? So we have this file called readme.md. So let's begin by seeing what git has for us. So there's a command called git status. Just execute the command called git status. So you should be able to see something like this. So git status is like any other normal status command. It shows the current state of your folder. So let's look at what git is saying here. Git is saying on branch master. So master is the default branch name that git gives to any of the branches. Like, I mean, when you start a fresh. So now what is branch? Don't get confused. It's just a way of saying, okay, I want to start on this version. So I am selecting, okay, I am by default on a branch called master. I am going to work on this. And tomorrow I can select another place, call another branch. So we'll explain in more detail what a branch is, right? So after git status, there's another command that we should be looking at. It's called git log. So git log is the history of git. So git log is the command that shows you what happened in the past, right? So currently it is showing author called Pooja Shah at this particular date and time. Added something called an initial commit. So initial commit is where we added the readme.md file, right? So initial commit is like, if you know how a tree structure is, initial commit is your root of the tree. This is where your repository is going to start. All right, so enough of jargon's commands. It's a, for some people it's very new, but for some people it's very basic and we want to move ahead. So let's see in real, okay, how it looks like. So what happened, whatever we did till now? So let's understand what we have until now. So if we look here, so what we have is this is GitHub. This is GitHub's view of your folder, how GitHub is seeing your folder, and this is your local. So when you did a Git clone, you took a copy of this folder here, right? So if you look closely, this IE is the initial commit that I showed you just now. So you can ignore this for now, we'll come back to it. So this IE is the initial commit and your master is also pointing to the same commit. So what is a commit? So commit is nothing but a checkpoint. Suppose you are making some continuous changes onto your files and you want some logical changes to group together and a particular checkpoint to which you may want to come back to, right? So that is something called a commit. So initial commit is nothing but the first file that we added and this master is nothing but a branch and it's a pointer. It's not something real, it's just a pointer which is pointing to this particular commit. Let me so far? Okay. Right? So now when you took a clone, what you did is you essentially copied this entire tree here, right? Now ignoring this, so there's something extra that came with this tree into your local. So there's some initial commit is the same, master is the same, but there's something called a head which came along with the clone. So what is head? Head is nothing but the pointer to the current state of your repository. Wherever you are currently in Git, head will point there. So simple to remember is like where your head is. So just your head, that's why it's pointing. So head is like your eyes are with your head. So whatever you are seeing currently is what head is. Got it? Okay. So we are going to understand each and everything by default, like one by one. So let's open your preferable editor. Like if you have sublime installed, then go for sublime or text editor or not pad whatever you work for you. We're going to code. So what we're going to do is in our sublime or something, we are going to open that repository. Everybody open that. Whichever path you have basically cloned, you know the path. So I'm assuming if you are following the sheet, you all have cloned it in documents. So just open that directory. We're going to create our first file basically. So I'm going to create a file called, I'll save it. So I want to say, I'm going to create a calculator file. So don't get confused with programming or something. We are just going to do basic code to understand. And what we want to do is we want to create like, this is the initial setup of the project. And I want to add something to it. So I'm creating an addition function, simple. So I'm writing in Python, but don't get confused. You can write in Java or whatever you work for you. So I say, hey, I want to add a function called add a comma p and I say return a plus b. Simple. I save it. I saved it just like my local file, I saved it. But what did I do here is, what did I do is I, still the git doesn't know it. I want git to understand this file and take it ahead. Take it ahead as in, it should understand the version of it. So what I'm going to do is the first command, if you see, I want to say add me. The command is simple. Okay. The principle we are going to learn here is, everything we do, we always use first command called status. We want to see what did we do. So we say git status. Git status is nothing but it will help you avoid any mistakes. So whenever you go back to the terminal, make it a habit to always do a git status first. So that you first see where you are and then only execute any further commands. Yeah. So it shows me that my file change has happened here. There's a file and it even tells me what I should do next. So it tells that, do you want to add a file? I just say that, okay, yes, I want to add. So I go ahead and I say this command git add and my file name. Let's do again what git status and see. So the color changing happens, but now you see there is something called, something called tracked and tracked. So you see in earlier case, it was showing untracked, but now it no longer shows that. So it means now git knows to start tracking it. But till now, still git cannot save the version of it. So what we need to do in real life, like how does your friend or your wife or your boyfriend knows that you are for them? You make a commitment, right? So we are going to commit, git commit. Git commit and what I'm going to do with a message, okay, I'm going to commit multiple things, multiple promises, I'm going to name those promises. So I say, hey, git add, I already did, minus m and message. So the commit message should be very obvious and clear. So I say added add function. So something happened. So let's take a break here and let's understand what we did until now. So we had a untracked file called calculator.py, right? So the moment you created a file in your text editor and you asked git what is the current status, it showed you that there is a file called calculator.py, but it is untracked. I have not tracked this file for you yet. So once you did git add, so what it did is it told git that now start tracking this file, right? So if you see git is saying it's a new file called calculator.py and whatever exists in this file, git will add it as it is to your git repository. So when you did git commit, what happened is this particular change, whatever you did, we created a checkpoint for it by this ID. So each commit comes with a commit ID, which is just a way to refer to that particular checkpoint, right? So this particular ID got created with the message that you gave that added add function, right? And it told you that you have added one file with two particular lines added to this file and this is a create mode as you can ignore this for now. So these are the file permissions. It shows some metadata along with it. So now let's look at our tree, what happened to our tree. So we were at I with initial commit, right? Now we have created another commit called A. Let's for the sake of simplicity, A is add, right? So we implemented our add function and we added a new commit, right? So let's see what happens to this tree when we did this. So your local head is the first thing that moves. Why? Why? It is pointing to the current state and your current state is this, where you have the add function, right? So your head moved there. Since you are working on the master branch itself, so even that reference moves. So this is where your master is also pointing now because master is also a pointer. So let's take a pause here and understand what a branch is, right? A branch is if we go back to our example of a blogger. So if you are a blogger, you will not be working on a single blog at one time, right? You might be writing three or four parallel blogs. So think of each blog as one branch and if you have a WordPress blog, then your WordPress is your GitHub or your main flow, workflow, right? So each of these blogs is one branch and whatever changes you are adding to those blogs and creating these particular commit checkpoints to that particular blog, those stay within that branch until you publish them. So, right? So that publishing is what we call bringing it back into the main flow. So we'll explain you further with the GitHub pull request how you bring back whatever you are doing. Clear to me? So we go ahead and we saw, okay. Yeah. Yeah. Sorry? Master is your current checked out branch basically. That's why master is moving along with head. So whenever head moves, one of the branch pointers will move depending on whatever branch you are at. So we'll show you how branching works. So we are going to see the difference in a few more comments where head will move but master will not move. Okay? So we go ahead with the, so we reached till 14 point in your sheet and we are going to see, okay, like 15th point, sorry. And we're going to see what we did. So we did what we want to know what we did in the like real life world. How we say we want to see the logs. So that way get log is the command. So you see, okay. The log line has increased one more log. It now shows the upper one more thing what I did. So this is a checkpoint which we were talking about. It means each state whatever we are doing it's getting saved. And that is where the version control is possible. So we are going to see again in further to actually have to make it understandable. So what it does is right now it's enough to understand that it has added my commit with some ID. That ID in graph we thought we told it A. Yeah. So there's a command for it called git show. Yeah. So if you say git show space the commit ID it will show what all changes are there in this particular commit. Yeah. So here it's saying that there was a new file added called calculator.py. And it shows the plus these are the two lines which were added in this particular commit. Then we know we know we talked enough about branching. Let's start using branches. So right now we are on master and we have added the add function. Assume that you started work and now you want to collaborate with your team and let them work individually on different functionality. So what are you going to do? You don't want them to mess up yours and you messing up there. So what would you do? You will start working on some other branch other branch as in other location basically. So what you will say, hey I want to create a branch. So it's a very simple command. You say git branch. And so if I want to see what branch I am on I would just say git branch. So it shows me in the pointer location it's branch. Now I want to say, I want to create a branch. So I would say git branch. Let's say I want to add a function called subtract. I created a branch but I want to work on it. So what would I say? Go and start working on it. So that word is called check out in git terms. Check out to my branch. So I say git check out my branch name. So now again what we will do first thing. Git status. Status. We should get used to this word a lot often. So what it says, it says me clearly that I am on a branch this and there is nothing to commit till now. Let's see what git branch says now. So earlier git branch was saying that we are on branch master. So git branch is now saying that we are on branch subtract and master is the inactive branch now. Master is not the active branch anymore. Any doubts with branch? Clear? All the tables clear? Okay. Next thing we are going to do is we are going to add. But why did we create subtract branch? To add a subtract function. Simple. Yeah. So what I'm going to do is I'm going to add a subtract function quickly to understand to move forward. So I'll just say subtract. We are good at copy pasting. So I'll say subtract a minus b and I want to save it again. So what should I do? Git status. Good. So I would see what we do. And now I have a curiosity. Okay. What is this change? Git show was showing me the committed ones. But right now I did not commit. So what would I do? There is a command called dip. Simple. Difference. Show me the difference I added. It shows me one more difference because I changed the line somehow. New line. Yeah. So there was no enter at that line. So now we have an enter. So it's showing that as a difference. So it shows me, okay. This is the difference I'm making. So now it is becoming clear. I will only save the specific things. I can see that if easily. So if you're also trying this commands and getting stuck, okay. How to come out? Column Q is the key. Right. So let's move it. I want to do next what? Add this file and say. So. So I just say add. And next thing, what should I do? Status. What should I do? Status. Status. You can do status as many times as you want and it will actually let you see what is happening as you are doing something. So let's see the difference here. What has happened? So I think a lot of people are getting confused with the get add command. So when we, so get add is not just to add a new file. Get add is the command to add changes, not the file. In, it happened to be like when we did the previous add, it was a new file. So if you look at it now, it's not saying new file. It's saying modified. No, you always need to add. Add is, so whatever changes you are making, right? So it is in this particular state, modified. And it is saying it is not yet staged for commit. So staged for commit is basically whenever you want to commit next, you won't get to include this file. So you may keep adding like three, four different files. And suppose you are editing four files and you don't want all four to be added to your commit. You want only three to go in your next commit. So you can choose what should go in your code. So get add will tell you that only add the changes from these three files, but don't include from the fourth file. Understood? Yeah, yeah, so it won't get added because you have never told get to add it. No, get will never track your file without adding it. So even if it is modified, suppose if I leave, if I leave this here, and if I do get commit, so we can just, I mean, I'll have to execute a complete command to go back to this state. And I can show you if I don't do get add, then what will happen? So basically get will not track your change. Unless you do get add, get will not track your change. Add is the way to tell get to track whatever you have done. Changes, not the file, all right? So let's move ahead and what should I do next? Commitment, commitment is important. So we say go and commit this file. So what should I give in the message? Add it's a track function. So I'll just say the track function, the track method, and I say get commit. Now what happened? What, how do I see get log? So I see the third commit also came. Subtract one on the top, right? Yeah. Sorry? We added. So like I told, add is not just don't think of it in terms of adding a file. So think of it in terms of adding a change, not the file, but the change. So let's go ahead and see what has changed in our tree now. We have made a commit, right? So something must have changed in our tree. So this is where we were before we made this commit, right? So what did we do first? We created a new branch, right? So what is a new branch? A new branch is nothing but a new pointer. So this is what happened when I did get branch and get checkout. It created a new branch called subtract, right? Which is pointing to the commit, which was there at that moment. Understood? Yeah. Right? And your head still stays there. Your master stays there. I did not change anything in terms of moving to a different version. I'm still at the same version called A, right? After this, what we did? We added a new function, right? And then we made a commit. So whenever we make a commit, a new commit is added here. Let's call this commit S as we added a subtract function here, right? So this is what happened when we did the commit. Now there will be two changes that happen along with this commit. So what will be the first change? Head moves. So head moves. Let's bring it closer to this, right? Head moves. And something else should also move along with head. Your current branch, not just any branch, your current branch, right? Your current branch was subtract. So subtract was created at A, but currently it is at B. I mean, so at S, right? Any doubts? So notice something else. Github doesn't know about whatever you are doing until now. Github is still thinking it has only one commit called initial commit, that's it. So unless we, so basically you should always understand this principle. This, your local and Github will never communicate unless you ask them to. So there are commands to ask them to communicate to each other, sync up. So we'll get to those commands. All right, so we did subtract addition and we understood, okay, we can actually have it on our local. Now it's time to throw our laptops. What does it mean? I want to save it somewhere else in the cloud. I can still be without my laptop. So what we're going to do is we are going to save it into Github. So for that, what I need to do is very first thing I need to do is understand a word called push. So why push? Because I want to push my local changes to my remote. So now a lot of words again, remote, local, we'll understand them better by doing this. So what we're going to do is we till now set, we till now created three commits, initial, addition, and subtract. We are going to say, hey, push all of these commits to my upper left, upper. So origin is nothing but a pointer to your remote repository. Origin is where you got it from. You did a clone, right? So that clone sets up a pointer called origin, which points to your Github repository. So you just say git push origin and then you give the branch name. So you are actually telling, you are actually telling push my changes from my local branch to my cloud branch. So that's called remote. Remote isn't, it's not in your local, it's somewhere else in the cloud. So you are just saying that. You get push origin, subtract, it should start pushing to your own code base. In which we can see actually there. So we'll just show you how this push is working. So what push is doing essentially is whenever you say push, whatever is the current state of your Github repository, it is pushed as it is to the remote. And now you are saying that I want to push only the subtract branch, right? So let's go back to that tree once. So when you are saying git push subtract, right? So your subtract is pointing here. So when you say git push, it doesn't just go push this S particular commit. It pushes the entire tree under it, right? So each of these commits has a way to refer to its ancestor or its parent. So if you see these linkages, it's a unidirectional relationship. So this S knows who its parent is. The moment I did this, okay, there is something called some subtract branch came with these three commits. So it has a copy now. Just like you save your photos in Google Cloud, right? So this is what we had there. And we asked it to look closely, not your master is pointing here, right? In your local. But this master is not moving because we never asked this master to move. We only told git that push my subtract branch along with its history. This is what it did. It took the history of this subtract branch and it pushed it and it updated the subtract pointer with GitHub. So GitHub now knows about your subtract branch until now GitHub was not aware that there's a branch called subtract. Give me a thumbs up when you say yes, we want to go ahead. Okay. So we understood about add, subtract, basic principles and we are now understand how it works. Let's go and again, let's go and add one more thing. So for example, sorry, subtract method by a branch called subtract. So tomorrow you might have a lot of code in that and you want to, it's still keep it safe. So we are going to understand how companies work in enterprise way. So we are going to do one more thing called keep that code, that branch also safe into some other branch like backup of backup. So what that word is called pull request. You use GitHub or you use any other cloud source control management tool that that word is like pull request. So what we're going to do is go to your, go to your. So just refresh your GitHub page. Actually, I'm committing to this. So if you see here, it's showing two branches. So one is master and one is the subtract branch that we created. So here is a subtract branch. And if I go to that branch, it shows me the code of the branch as well that we added a calculator file with this changes. So now what we're going to do is, we are going to tell, so this is like this. So actually actually want to say that I am done my subtract function till. Subtract function everything is working fine. I want to save it. I want to give it to the next one so that this is not missed. I can still work on my subtract branch and do things however I want to. So what we are going to do is we're going to hit a button called pull request. There are new pull requests. So you will see something like this. We're going. This is basically because you have forked it. So GitHub tracks all the folks that happen on our repository. So usually if you are in your local system, you should not see this. So you will actually see something like this. So there is a left side base and a right side head. So now we actually, we would understand, okay, why something called, something is called head and something called head because our head was there. So our own branch basically and base is something where actually we want to put our code from head. From head. So what we're going to do is this thing clear, create a pull request and we are going to name it properly that added subtract function. So in real life you will be adding so many things. So you will be actually describing all those line by line here. Like what did we do in this code base and you can actually create this pull request. See the changes again, whatever you did in local, get diffuse all right, before merging it. You can see. Right now we added everything from the subtract branch. Addition as well as subtract. So if you look closely, it's saying there are two commits which are going to go into the master branch. So let's look at the tree once again. So if you see here, this is GitHub. This is GitHub's master branch, right? And it is pointing here. So when we did a pull request from subtract to master, what we essentially did is we asked get to bring these changes into this branch, right? The pull request is nothing but a request to bring your changes into some other branch, right? So usually in most of the systems, master is your production branch which is running in production. So you want to test everything in your personal branch, make sure everything is working fine and then only raise a pull request to your one of your main branches which track the overall code base, right? So it is saying there are two commits, these two particular commits, and it is showing the changes from both of them together in the pull request. So GitHub is nothing but a visual way to do all these things. So actually whatever we are doing by GitHub, all of that can be done via your command line as well. So GitHub is just a simplified way to do things. There are some GitHub UIs, I mean not GitHub UIs, Git tools, desktop tools which allow you to do that. But yeah, source tree or something which allow you to choose only these particular lines which you want to add. What they do essentially is they create a copy and they let you add only those particular lines. But from the command line, I'm not sure if it is directly possible. If it's a different file, I'll have to check if you can commit partial changes from a single file via command line because the git add command takes a file path. If it's a different file, of course you can, you can say that only add these changes, clear? Yeah, so yeah, that is possible. So let me repeat the question for everyone. So the question that she asked us, if we are working on two different branches and we want to bring the changes from one particular file from one of the branches into the another branch. So yes, that is possible. There's something called, you have to check out to that particular one and you have to take the, so you have to either what, if it is present in a single commit, then there's something called git cherry pick. So cherry pick does nothing but takes the changes from a particular commit and applies it wherever you ask. Like name says cherry pick. Okay, I think we should connect after the session. We'll just finish off whatever we've planned. So we'll talk to you after the session. The request, everybody there doing along with or lagging behind with how many? Okay, cool. So here are behind, just pair with them so that we can go ahead. So why we are showing this tool is because this actually gives you access to actually, so in real life you will have this tons of changes in this. So you want somebody to review your code. It's called peer review. So you want somebody to review before actually making it live. So that's where they can actually come here, come in, ask for review and request changes, things like that. So right now it's me only, so I'm just going ahead and I say merge this. I'm going to do, yeah. So GitHub provides three ways to merge. So there's something called create a merge commit. So merge commit is nothing but it will create a new commit on top of this called merge commit and it will move the pointers there. So there's something called squash and merge. So what squash and merge does is you had two commits, right? A and S. So squash and merge says that whatever many number of commits you have, take the changes from all of them, convert it into one single commit and put that commit in my base branch. That base branch is master here, right? So this might be one of the very frequently used cases in terms of enterprise when you use GitHub, right? And so there's one more thing that you need to understand here. When, so a commit is immutable. Keep this in mind always. If you have committed something and Git has created a particular commit, it is immutable, you can never change that commit, right? So you can create new commits which are copy of this but you can never go and amend a commit. So when it says squash and merge, what it is going to do is it is going to take the changes from all these commits and create a new commit for you. Now for simplicity, we go ahead with only create a merge commit and I say merge. So we're going to see what happened. The moment we did this, now I want you to tell what happened. We have actually merged subtract branch to master. So we're going to go back to tree. Now I want to know what happened. What should we do? Sorry? Master points to S, yes. So master starts pointing to S because, and nothing we see in local because we are not dealing with local anymore. We had the changes already. We created a pull request to the cloud. Sorry? Yeah, that's where we are coming to. So we'll show you a real example of a conflict, how conflicts happen. So now something worth noticing here. So your GitHub master has moved ahead. Your GitHub master is pointing to S while your local master is still pointing to A. So this is where both of them will keep working individually and they will keep moving here and there. And frequently you'll have to sync them up with each other. And when you think only that that time it will be synced, otherwise everybody can work. Everybody is in, your team members can work in different branches and can collaborate without actually changing each other's thing. And in little complexity, we're going to understand about the conflicts. So let me explain, let me show you an example of how a conflict can occur. So when do you think a conflict can occur? Sorry? So not just same file, but the same location inside the same file. So within the same file, if somebody is editing line number two and somebody is editing line number five, there will not be a conflict. But if two people are trying to make changes to the same line number within the file, that is when conflicts occur. And Git being a dump system does not know which one to keep. That is where human intervention is needed for you to tell which one of these should be kept. So let me show you an example. So in interest of time, I'll go a little fast so that I can actually show you a conflict and I'll also show you how to resolve it. So this you do not get to do simultaneously? So if you are able to keep up very well, if not able to keep up, we can talk after the session. Right? So we are currently at subtract branch. So I'm going to go and check out two master branch. So now my master branch, this is my local and it is pointing to commit A, right? But my remote master is ahead. So there's something called Git pull origin branch name. So using this command, you can pull changes from any branch into your current branch. So when I say Git pull origin master, I mean sync my current branch with master from origin. To the cloud we said push. So now when I say Git pull origin master, so Git said it changed the commit from this to this and it brought one file change. So what did this Git pull do to my local Git tree? This is my local Git tree. Yeah, so your master moves to S now. This is what happened with Git pull origin master. So there's, if you don't specify Git pull, if you do only Git pull, then what essentially happens is the entire tree sync, not just your current branch, but the entire repository sync. So usually that is not the preferred way because when you're working in an enterprise, it might bring a lot of changes into your local. So you should always bring in only what you need from the remote, right? So, sorry. All the changes meaning all the branches, all the commits, whichever somebody has made. So it will bring the entire metadata into your local. So no, if there are conflicts, then whatever it did here, right? It said I did the fast forward merge, basically a fast forward pull. So if there are conflicts, it will stop here and it will show you that there is a conflict. I'll show you a real example. So let me check out. So let's assume that we have added add and subtract until now. And now there are two people who are going to add the next two functions to this file. So one person is going to add the multiply function, one person is going to add the divide function, right? So let's assume that Pooja is going to add the multiply function. So what she would do now is she would check out minus B to multiply. So this is a shortcut for saying get branch and then get check out. So get check out minus B multiply is nothing but get branch multiply and get check out multiply. It's a way to say it in a single line. So it says switch to a new branch multiply, right? So this is where I am, right? What I do is I add a new function called multiply. So git status shows that I have modified the file called calculator.py, right? Yeah, so if I do git commit minus m added multiply. So what did git say? Git says there are unstage changes which are not committed, I mean which are not added and there are no other changes to commit. It says no changes added to commit. So it will not create a commit for you. So only when I do git add, so there is a easier way to do this. So you can just say git commit minus a m. So if you say git commit minus a m, it is add and commit. So if I do git commit minus a m, it will create the commit for me. So it says I am on branch multiply and I've added this new commit called added multiply. So what do I need to do next? I need to push this branch to origin. With me so far, whatever we did with the subtract branch, we did it again with the multiply branch. We added a new function called multiply after the subtract function, right? So now my branch multiply is already pushed to GitHub. Any doubts? Cool. So now let's switch to another user. So let's assume puja was the one adding the multiply function. Now let's assume aksha is another person working on the same branch, on the same repository and I'm going to add the division function, right? So what would I do here? So it says I'm on branch master. Let me go back and come back here. So this is where we were. We pushed our branch to remote, multiply branch, right? So let's assume we were working both of us in parallel. So let's switch to the second user and see what he's doing, right? So I am on current master branch and what I'll do first thing is I'll first sync my master to remote master. So usually whenever you are checking out a branch, basically whenever you are branching out, you should make sure that whatever base branch you are branching out from is synced up with the remote so that you don't branch out from an older point. If you branch out from an older point, like suppose if I branch, if I did not do this get full, then this master was pointing to initial commit. It was not pointing to S, right? So I'm not working on latest code in that sense. So in that sense you are branching out from an outdated version of master. So nothing, it will not cause any problems, but it may cause a little bit of complications at the time of merging, right? So it's always recommended to pull and then branch out, right? So if you see it already brought the calculator file for me, so if I do, so this file only contains add and subtract so far, right? Why? We did not merge the multiplier into master. We only pushed the branch and let it be, got it? So now let's go ahead and modify this. No, so whenever you are branch, that's what I'm doing. Did I pull the multiply branch? No, right? I am on the master branch right now. So I'm going to branch out from master because for me as a person who's working on something, master is the source of truth. Whatever master says it, what it is. So because multiply like we pushed the branch, we may never even merge it. So that way I should not be ever considering multiply as my base. I should always be considering master as my base, right? So this is our current master state where it contains the subtract function, right? And this master does not know about the multiply function. So as somebody new who's going to add a function, what I would do here is I would just implement the division function. So what did I do? I just added a divide function just under subtract, right? So do you see a conflict here now? Which will occur. It has not occurred yet. It will occur, right? So let's go back here and see what Git status says. So Git status is saying I am on branch master and I have some uncommitted changes. I have made some changes but I have not committed. So this is a very common mistake that you may do. I was on master and I wanted to check out to a different branch and then make the changes but I did not. So but Git allows you to do that. I can still check out to a new branch. It will not prevent me from doing that. So I'll just say Git check out minus B divide and it will bring whatever changes I made from master to this branch. So it will now say I'm on branch divide with the same modified file, right? So now I'll just commit this. We haven't set the, so this is what you will get if you don't do Git config. So Git doesn't know you, who you are. So Git will first ask you to set a configuration. So but Git will not prevent you from using it. So what it did is it took the local user of your Macbook and it assumed that this local Macbook user is doing it. So it took that particular username and the email ID. I mean the host name. So otherwise Git is saying that you should ideally set your username and email ID, right? So now I can just do Git status once more. So I'm on branch divide with no changes and I just push this with me so far. So whenever your push creates a new branch in remote, Git says here that it created a new branch in remote, right? So let's go back to GitHub and see what's happening with GitHub now. So now, what should we do? Now GitHub says there are four branches. Master, multiply, divide, subtract. So subtract is already merged. So let's ignore subtract. So multiply and divide are the two new branches that we created. And now this is in a real life situation. It depends who brings their changes into master first. So let's assume that Pooja raises our PR first. So PR is nothing but pull request. So let's say multiplies pull request is being raised to master. And what is it showing? It's showing a new multiply function that was added. So master doesn't know about divide yet, right? So it's showing that this multiply changes are mergeable to master, because it's not conflicting with anything. We just added two new lines. That's it. So let's go ahead and, so let's go back to a practical situation. Both of them may raise the PR in parallel, right? So let's raise the second pull request also. Suppose both of them finished at the same time and they both raised the pull request. So what is this pull request showing? This pull request is saying divide is added under subtract, right? Any doubts? So now at GitHub, we have two open pull requests. One wants to add multiply, one wants to add divide. But let's see what happens if we try merging both of them. So we have the multiply branch, or if you, let's do it the other way. We added multiply first and divide later. Let's merge divide first. Let's assume divide is merged first. So it allowed me to merge divide, divide is added. Let me go back to the second pull request and see what it says now. So this multiply was mergeable earlier, but now it's saying there's a conflict in calculator.py, which means you cannot merge your multiply branch into master unless you resolve this commit, right? So to resolve the commit, what you have to do is you have to go back to your, so GitHub now recently added something called resolve conflicts here, where you can edit and conflict resolve it right here, but it's not recommended. Better to go back to what you are comfortable with, your own editor. So let's go back to multiplies editor. This is my multiply, right? So this multiply branch does not know about the conflict yet. Why? Sorry? Yeah, so I didn't do git pull, but nothing will happen if I do git pull. I have not modified the multiply branch. Did I make any change to the multiply branch? No, right? So should pulling make any difference? Pulling, so pulling multiply branch. Should pulling multiply branch make any difference? Sorry? I am somebody very anti-reverse, we'll talk on that later. So let's see, so what we want to do, we want to merge the multiply branch into master and master is saying that you have something which I am not comfortable with. So what do you need to do? You need to first bring master to you. So what you need to do is you need to say git pull origin master, right? Yes, exactly. So we have to get what master has and then see what is it which is causing the conflict. So now let's see what git says. Git says I pulled this master and I am having a conflict in calculator.py. Automatic merge has failed. So this is where a human intervention and a merge conflict resolution is needed. So let's go back to our editor. So sublime is saying there's a merge conflict. So this is how a merge conflict looks like. Whenever you get a merge conflict, this is what you will see. So the merge conflict starts from this particular token. It says that this is the start of conflict. This is the start, finish of the first section, right? And this is what it says, head. This is where you are. What is head? Head is where you are. And you want to say after subtract add multiply, right? And this is the commit ID which is conflicting with this. This commit ID saying I want to have divide here. Choose both of them in separate sections. So we can choose which section we want to keep. So in our case, it is very easy to resolve this conflict because we want to keep both of them in a practical scenario. It may be a bit more complex where you may, it may not be as simple as keeping both of them. It could be like some part has to be taken from here. Some part has to be taken from here. And then you need to remove all these conflicts and then give us single version of this file to get, right? So let's assume that this multiply had a enter here, right? And we want to keep this space. So that's where I would take something from here and something from there. Sorry, let's, sorry, my bad. So the enter is here with divide. So we want to keep this and we want to keep that. So the simplest way to resolve the merge conflict is, if in our case, like we want to keep both, just remove everything and we have the version of the file that we need. Essentially, after you remove the conflict, the conflicted section, you should see what you want to see, like what you want actually to be there. I want divide and multiply both to be there. So I'm having both. If there is something that needs to be removed, this is where you should remove it. And a single file may get multiple such conflicts. This is just one conflict because it's a very small file. If you have a large file with multiple people editing at various places, so a single file may get multiple conflicts. Suppose you can get a conflict from line number 50 to 55 and another conflict that line number 120 to 123, whatever. Yeah, so the UI tools like source tree, all of them allow you to do this in a better way. So it will show you one version here, one version here and it will show you after merging what you want to keep. It will simplify the merging process for you, but essentially this is what merging means. There are two sections and you need to choose what to keep from which section and essentially create a new section which should go to get it. Right? So now we resolve the conflict, let's go ahead and so let's, after you resolve the conflict, if you see here, what does get status show? Get status is showing that this calculator.py has been modified from two sources, both modified meaning the remote that you pulled and your local, both have modified, right? So after you resolve the conflict, you need to say git add, git add calculator.py. So in my git status, what do I see? I see that calculator.py has been modified and it's ready to be committed. And there's one important thing to be noticed here. Whenever you are resolving a conflict, don't add a commit message because whenever, so this is where a merge commit is created and a merge commit is little bit different from your standard commit that you do. Your standard commit has a single parent, but merge commit comes from two parents because it is merging two of these commits together. So git is specifically saying use git commit to conclude merge, right? So what we do is we just do git commit. We don't do minus m. Our editor is a little bit screwed up otherwise. So you can try doing in your local if you are somebody's following up. So once you say git commit, it will open the editor for you where it will give you the commit message which says merged branch master into multiply. That will be the default commit message which will come. And after that you just exit the editor and it will create this particular commit. The reason why you should not give a commit message to a merge commit is the merge commit comes with a default message which is easy to track when you are looking at git history that this is the point where you merged something. If you change it to something like this, it will look very similar to all of your other commits and you will not be able to see when you actually did a merge. Where, sorry? So I showed you right there was a button called resolve conflicts there. So if you click on that button, it will open up a UI for you where you can do the same thing which I did with the editor. Oh, so you want to do it across these two pull requests. So no, that is not, so it can get very complex when you are in a real life scenario where there are hundreds of people working on it. So it's not practical, so it is always recommended to go always to the source of truth which is your master. So all PRs should be merged to the source of truth. No, not just in message. So merge commit is when you get a conflict, it creates a new commit that commit has two parents that this is a merge of these two. So we have resolved the conflict, merge two different branches to what? I don't think that should happen because as long as there is a commit, there has to be some difference. It may so happen that you have one commit which is adding two lines, a second commit which is removing these two lines. So essentially you may get a zero diff, basically no diff, but you will still end up with a difference of two commits. So these two commits will still come into your tree. Yeah, so we can look at your problem after the session and probably we can figure out what's happening. So we have resolved the conflict, so let's go ahead with pushing it. Get push, origin, multiply. So we resolved the conflict and we have pushed it to GitHub. Now let's see what we see in GitHub. So GitHub is now saying it's ready to merge. It's mergeable to master branch. There's no conflict. So let's see the changes that it is showing. So now. But in GitHub, we again saw the diff, the diff was not correct. So we can again go and fix our mistake. So that's why it's like advice to check in your local by taking a diff as well as in your source control. Okay, whatever I resolved was never saved. Now it's saved. So this is why you should always check get diff. I did not check diff before committing. So now it's saying I have removed this because I have already added this and committed this. You should never add the conflict and push it. Right? So we're just doing resolving conflict and then pushing it in. Yeah. Thank you. Yeah, so let's see what happened here. So now it's showing these are the changes I've added to the multiply branch. So I've added a function called multiply and I've also added one enter at the end. So these are the changes which the multiply branch is adding into master. So now let's go ahead and merge this into master. So both our branches are now merged. Our master contains what we wanted it to contain. So let's see what our master contains. So this is what our master contains. Add, subtract, multiply, divide. That is what we wanted it to have. So GitHub has a lot of features here and there which you can play with once you get used to it. How about these commands and we saw, okay, how can we work? We saw that push, pull, and merge, resolving conflict. And so we are about to end here and we're going to summarize this, what we did. We understood what, why, and poking and cloning, merging, resolving conflict. So we are open for the questions now. Like if you have particular questions that you face or you have the ready problem we can solve. Yeah. Can we get the mic there? There. I know the coffee is much needed, but yeah. So the way Git works is a bit different from how SVN works. So the concept of branching and merging it back, SVN has a single view of your folder. So I think, I mean, I would not be able to give you a very detailed answer here because I have been born into the Git generation. The generation before me was born into the SVN generation. So I'll have to like look up the difference and then I can probably give you a better answer. I'm always working on master. Mine is also screwed up. There's no concept of local or remote. I'm always working on my remote. That's the advantage Git gives. You can work safely in your own, your own location basically, in white words. Sorry, but Git can do that as well, right? You don't add the changes and it stays. Okay, I got your point. So if you are pulling from remote, you can pull specific parts of the remote, not the entire remote. It always pulls everything. Hey, so the question that I have is, let's say I do a commit and I find out that on the cloud, that is my branch on the cloud, there are some files which are unwanted. Okay. I have accidentally checked in that file. Now how do I remove that? This is one problem that I have and a subset of the problem is, let's say I have committed to my branch on the cloud like three times and the third commit, not the recent one, the third commit before that has an unwanted file. So how do you remove unwanted files in the recent commit as well as like two or three commits before? I'm not checked into the master. I mean, I've not merged to the master. This is on my branch on the remote. So if it is your specific branch and you know that it is not going to affect anyone else. So there are multiple ways you can do it. You can either revert that particular commit only. So revert is basically anti-committer. Whatever you add in the commit, revert is the negative diff of that, right? So you can add a revert and then you can add again whatever specifically you need. Or if you are very, if you want to do another way, you can just roll back your local to wherever you want it to be, then add whatever you want and then do a force push. But force push is not recommended because.