Basic git commands everyone should know about

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to a special episode where I'll be telling you about basic git commands so git is used almost everywhere in the industries and when you start in a company they expect you to know some git commands so it's get is very used we'll get to the so school management system in case you didn't know and it's also very useful to keep track of your work and share it with others so if you're working on a project and want to open-source it or simply when you're working on a project with a bunch of other people or when you're working on project alone it's it's very useful so just imagine like you're working in a project and you're working on a file and someone else is also working on that file and you will have a lot of conflicts so you must wait for the other to finish work or the other person should wait for you to finish work before you can start building something on that file so these kind of things and conflicts can be avoided if you use git the most important thing is that if you use it properly you are never going to lose your work so if you have a power failure or hard drive failure or anything like that and your hard work hard drive crashes or is stolen or something but you your work is always going to be with you and you can work from anywhere from what I've seen is that many beginners have a lot of difficulties understanding get when it comes to get they face a lot of difficulties so when they start in a company the company expects you to know about git learn about good but you don't know anything and it's going to hurt a lot so in this video I'm going to teach you about certain basic git commands so some commands some basic git commands that you should always know and I must tell you I'm not an expert and yet it's huge but there are certain commands I can tell you about and you can get away with them and as you progress as you learn more more about get you will try to you can try to Google your problems and related to it and you will find solutions either on Stack Overflow or there are so many resources so let's get started and let's learn a little bit about get today so today I'm going to be using github you can use anything you want you can use bitbucket if you want so that's not a problem get hub is just a personal preference here but the commands are going to be the same and anything they choose so let's get started I've moved to my terminal so you can use any terminal you want I'm going to tell you about git commands using the terminal not using some ID so it's very easy if you are using an IDE so so I've created a new folder called git underscore test you can create anything any kind of project so you see this folder is empty right now there's nothing in it so first things first what we are going to do is we are going to configure the username and email that appears with all our git commits now what comments are I'm going to come back to that but first we need to configure so get conflict - - global user dot name and then you can write your name ok that's how you enter your user name and you press Enter I've already done that so I'm not going to do it again and the second thing is you do user dot email and then you enter your email associated with your github account or it should be associated with your github account or your bitbucket account so this for this video we are going to use github okay so once you're done with that we can start with basic it so first of all you created a new folder you're working on a new project first thing you do is get in it so that's only required when it's not a github agate repo a good repository so let's say let's say you must have seen a lot of git commands that I write in my previous videos so if I do get a dot so it gives you okay this is not a git repository there is no dot git folder so what what we are going to do first is to make it a git repository so you can just right get in it and it initialized empty repository no we take a look at file and there is a dot git folder let's say it's a git repository there are a lot of things inside that you can go and take a look but I'm not going to discuss them in my video in this video so now we have we have the dot git okay that's fine and you can also see that here it changed to master so it automatically moved to a new branch this is called a branch master branch so whenever you initialize a git repository either on github or locally a branch will be created called master and master will be the only branch that would exist for now so now what we do is we can add some stuff so one of the basic things to add is get ignore so you can get different kinds who could ignore if you're working on a Python project if you just go to github it has a bunch of templates for Python projects and different different kinds of projects so you can just get it get ignored from there or you can create your own get ignore so just as an example I'm going to create my own to get ignore so I know um you can use any text editor that you want it ignore so now here I will say okay start CSV and save this file so I've saved dot a new file called dot git ignore and it has only one entry for now let's start off CSV so what does it mean is when I add anything to my repository which is a dot CSV file it won't be pushed to remote so what is remote I'll also come back to that later but you must know that okay you don't want to push large files or data files or experimental files so if you create a Jupiter notebook for your own experiments you must add it to get ignore or create a new folder and say you can also do something like notebooks slash and then it knows that whatever is in your pool did notebooks it's not going to get pushed took it ok so get in it did ignore get in it if it's all not already a repository so if it's a new project that you're working on then only you in it otherwise it's already initiated you don't need that but you always need to configure your username and your user email that's required so we got get ignored and now what's next the next thing is we see that this is this is a hidden file so now you see that this is a file here so you can always see the status of your current branch and you can type git status so what does good status tell us it tells us a few things and it first first of all it tells me I'm on branch master but I'm using I'm using a search and I'm also using some plugins over there so I always know which branch I'm on and it's very important to know which branch you're working on and if you look at vs code it also knows that which branch I'm working on so you can also look here if you're using vs code so I'm on branch master I have no commits till now and I have one untracked file so it is telling me use git add file to include in what will be committed okay so now what we do is we do get add dot git ignore the file that we just created and the file gets added so you don't you don't have any errors file gets added now you don't get status and then you see that the status has changed okay so now you have a new file dot git ignore and it tells you okay if you want to remove and then you can use this command but we don't want to do that so if you have a new file instead of untracked file now it's in changes to be committed section and now if I if I do like now I can commit this file so I can do git commit minus M so minus M is the message so you all you should always provide a useful commit message and you don't have to commit each and every change that you make but only the major changes so get to commit minus M adding and get ignore file okay now you see it gives you this commit ID and it says one file has changed and two insurance insertions have been made you created a new file called git ignore now nothing will change here because it's going to be the same now you have created a local repository so what you can also do now is create a remote repository and that will be either on github or bitbucket so we can we can go to github some most familiar with that and I create a new repository so I will just name it the same get underscore test and it's a public repository I don't care and I don't choose anything from here I'd say okay this is just test ripoff and I create this repository okay so now it gives me this address or HTTPS so you can use both if you use SSH you have to configure a little bit more so you have to what you have to do is first you have you have to create a search key using ssh-keygen so that's also a simple command as such - key gen this will generate a SSH key for you and it will also tell you where it's located so it's usually located in dot SSH / IDRs a dot pub so that's your public key that ssh-keygen will generate then you go to your github account settings click on as a search Keys and then you add then you copy paste whatever is the content of your SSH sorry ID RSA dot-eu B so the public key you add it here then you can use SSH otherwise you can use HTTPS it's going to ask you for your password so that's not a big problem for us anyways so the next thing so do we I have one figure SSH I can use this to search so I'll go here and I'm going to copy this so I have I have copied it now what I do is it's also telling me what you can do okay so I'm going to copy this command instead so it tells you you can add a remote repo so do any kind of people that you already have so we already have this have done this repo we have get in it and everything else so I'm just going to copy this command git remote add origin and then your path to your repository and it works successfully so let me clear let's me see ok it works fine now what you have is you have already added the repository so now and you can push your changes so I can just do ok I can do git status so it will tell me I don't have anything to comment because I have already committed my changes before so I can just do git push so it tells me current branch master has no upstream branch it's ok so you have to do it all at once you can also set it as upstream branch so let me see get push - - origin master sorry okay good push origin master North - - so yeah so now your changes are pushed so you are saying that you're pushing to origin branch master you can also use git push directly and when you when you get a get something like this what you can do is you can also use copy baseness it's basically that so now I go back to my get repository here and I will refresh the page I see okay now I have my files here that's very nice right let's see start out CSV notebook slash fine now I can go and create some more stuff so let's clear this so now let's create a new file called testify but before that we can also copy some stuff so let me see what I have so I think from one of I I have a lot of CSV data data sets right so let me see input train dot CSV I have that so I will just going to copy and paste it here so now you see that I have a training dot CSV file here okay so now what does get say nothing to commit it's because you have already added star dot CSV to you're getting node so this file will never be pushed so you you should add things like the things that you won't want to push to remote you should add those to get ignore like you if you have passwords or some keys that you don't want to share with anybody so you should you can add them to get ignore those files names to get ignore and then you can put your key there so now I have the strain dots you see but if I if I do like CP training dot CSV and if I just change the extension train the CSV P okay so now I'm going to do get status again and it's going to say I have a file but uh we are not going to do that so I'm going to remove train dot CSV be okay and now what we can do is we can create a new file let's let's say we create a new desktop I and I don't know what what do we want to do here okay let's let's write some simple code import pause PD so we already have this test dot CSV okay so what I'm going to do is not follow any conventions for now and just wanna write some code VD dot read CSV and I'm going to say it train dot CSV and I think it was the n roll maybe read hundred rows and print the F dot that that's what my code is going to do okay let's see fightin justify does it work yeah it does work so you have some yeah some bunch of data you don't have to worry about that and now what what we can do is we can do get status I mean so I have just out by I can also do something like get okay we'll come to that later so now I do get add so you can also do get ad space dot or you can just type the file names that you want to add so if you do not add dot it adds everything that you have changed so I've added everything that I've changed and now I can do get comment add a new test look line okay so now I have a new test respire and I can just push it so now yeah I should have I should have already set it at upstream then won't ask you again so let's try I don't know why this is not working okay let me copy this okay so in our next commit is not going to complain okay now I go back to get refresh and see that I have this testify that we just wrote simply and here you see the branch so now you can see that this is in master branch so what happens in most of the companies or industries is or any open source project you have a master branch which is the most stable branch let people are using so master branch contains the most stable code so this is a convention it can be different in different companies or different industries or different open source projects but master branch mostly contains the most stable code that people can use so if when you're making changes to the code you want to test your code properly so even when like let's say you're building a simple machine learning model and you're building in on some data and you want to be like you want to when you improve so let's say you built a simple logistic regression model on text classification data so you create one model you create a basic class segregation model and now you want to improve on that model so you don't first of all what you want to do is you want to create all these changes in your master branch make it stable so stable that people can use it and then you can continue making improvements on that okay so when you do when you like continue making improvements you don't want to do that in master branch for that you should create a new branch so we can create a new branch from any branch so whenever we create a new branch we create a copy of that branch at that point of point in time so if I have like four people working on a project so all of them can create their own improvements runs or feature branch from master branch so all of them will have one copy of master branch and they will work on that and when they're done they will tell me what that they are done and we will come to that later so right now we don't have any branch you have a master branch okay and let's say my desktop is my production ready file if I make any changes there people are going to see it in there in the software so I have tests of Pi so what I'm going to do is I'm going to add some more stuff to desktop PI so first of all I will create a branch so there is a command called git branch so it tells you there is master and your own master okay but now we can we can create a new branch using several different kinds of comma not several but couple of different kinds of commands so we can do get branch and name of the branch we can also do get checkout - d that create a new branch and then name of the branch so we can use them both branch and then your branch should be like it should say what you're doing so let's say I have a branch I create a branch called date dust so my master branch is fixed now and I created this new branch called update test but then I check the status so I'm still on the branch master there is a branch called update test but I'm still on master so I do get branch that will also going that is also going to tell me the same thing but you have a master branch and update test what's your on master so now what we do is we have to check out the new branch so we can do get check out and update tests ok one more thing if you had used git checkout - B you would automatically move to the new branch so you don't have to do two steps so now I'm in update test so you see it has changed here it has change here I will do it status and it has changed here okay there is one more command called git log and get log tells you what kind of commits have already been done so whenever you are wondering ok what happened where it is a code break you can go and look at different commits so when you do get log you see this one comes from origin master master ok master branch and you created update test from here and this was the first comment adding a git ignore file by me and then the second commit ok and so you have things like this and now what you can do you can also do it in a pretty way yeah this gives you one liner so you can do a lot of cool things here okay so now you have you have this update test branch and now you are going to make some changes so you make your changes as normal so if you see you have the same files and you can you can make multiple changes so let's make two changes I'm going to do I'm going to go to get ignore and I'm going to say okay I have starred what's easy but I'm going to have started zip zip files at some point I'm going to ignore them so I made one change and I have not done anything yet so if I do get status I'm modified one file and I'm also going to modify it that's not why not production file so I'm going to say this in this new version people are also going to see value count so that's my new feature okay and then I run test dot PI everything works fine now I have the head now I have this I took it it is so now I modified multiple files so what I told you first you can do get add a file name or you can also do get add dot to include all of them but there there are more things so if you want to discard the changes that you made so you can do get check out you can do also we also do get stash okay so now I do get add not so get that dot that should include everything and then I can do get comment - em you can do get status and you can check again but I know already what's going to happen so we get comment - em and then our message so added nougat ignore and new new feature in just okay and then you do it push so it's going to give me this error I'm gonna copy that I don't know why it never works okay and now I have pushed it to github refresh a refresh there is no change okay but now you have a new branch update on let's go test and here it also tells you you have a new branch so what you can do is you can always go to any branch from this list let's go to update test and now we are here and then you have you have buttons like so here it's telling me that I can compare and pull requests right but you I can right so I can just click on compare and pull requests and it creates a new pull request for me and if I scroll down I will see what are the changes I made which is very important so what are the changes that you made you must know that so now you can click on create pull request and it's going to create a pull request for you okay so it says I don't have any conflicts so conflicts are when someone else has changed something in master branch then you might have conflict and gives me option to add some reviewers and add some labels projects whatever and it also gives me what if the files changed what are the different commits so you can see the different commits here and then yeah reviewers will review your pull request and then you can merge it so here I it says that I want to merge one commit into master from update test so update test to master so I'm just going to merge this pull request okay so much just pull request and now I delete the branch and no longer need the branch and I go to code and now I'm in master branch you click on testify and then I see that I have the new line pretty cool so now we go back to our terminal and now we are on this update underscore test run so now I'm going to go I have to go to go back to master branch so I do get check out master I reach master branch now they're having some changes in master branch so I do get full and yeah I got my new changes so whenever you go to a branch you know that multiple people have been working on or you have been working from different places you you go to the branch you do get pull you can also do get fetch and then there is also get merge but get fetch and get merge or something that you should learn on your own you can do git pull and get fetch anytime you want from anywhere so you should always have the latest changes in the branch so now we are going to create two different branches and I'm going to show you how to resolve conflicts so I make a new branch test one and I have moved to test one branch now I'm going to change the file called the testify file so I will say that I add probably in this time I don't add anything but I delete it okay so I have deleted one line of code and we save it and now we have we will have one file change so I'm quickly going to add this okay remove on line and then get push in test one okay so we are pushed our changes so now if I create a branch here I will actually be creating a branch from test one not from master so I have to go back okay check out master and I'm here and now I can create a new branch again I can do git pull you can create a new branch it says it's already up to date so there's nothing new in master branch so to check out - be test - okay and I say ok now I'm in test to do Nano Desktop ice so I had to remove this line of code here right so let's make a few changes and 20 I'm saying that I want to print 20 instead and get a dart coming to mind a fan at 20 good push origin just do so now I got multiple branches and I'm in my git repository I see that it gives me multiple branches here but I can also see it here so I'm going to go to test one and we will create food requests both both of them so create pull request okay so now you have one pull request to remove one line and let's go back and create another pull request at 20 line now to create a conflict we have to merge this one first I think okay so remove one line we removed print and we are going to merge this pull request so now in this broadcast has merged to master branch so your master branch now as now is not up-to-date so your branch had 20 it's not up-to-date with master anymore and it should give me some conflicts because it changes something that has already been changed okay so this is like you should always have your branch up-to-date with the branch you want to merge it to so right now we're merging test two to faster and it's not to date and it can cause issues if I merge this so if I was it's going to but so what I can do is I'm on death to resolve the context you using github the web we but we are going to do it income online so what we are going to do is we are going to check out master and get pool so I will get some new changes in master now I go back to test two and then I say merge the changes from master branch to this branch and it's going to tell me that I have conflicts okay so we got it tells me that I have a conflict in testify so sometimes you won't have fun most of the times you won't have Conway sometimes you can have one fix and when you have conflicts you have to fix them so I'm going to do nano test or cry and we see how conflicts look like so it tells me that master branch didn't have this line I mean it can be more but your branch has this line so what I'm going to do is I have to say here what I want to keep what I want to delete and you can also do it using vs code so this part I can show you using vs code it's much easier so we go to vs code and we have the same desktop by and here it tells me so this is your green one is your current change and when you're merging with monster it's your incoming change so what you can do is what you want to keep whether you want to keep the incoming change or you rather want to keep the current change or you have to keep both the changes so in this case I will say okay I want to keep the current change and my conflict is resolved I save this file move back and I do get a dot adds everything and then instead of the commit message I'm going to do just get commit enter and it's going to show me that it's a merge commit and I have resolved some conflicts so I save that file and then I do git push origin test - okay so Bush's fine and here the page has refreshed I see that there is now a new commit merge run master into test two and one file has changed and it doesn't complain about any conflict so I can simply or just pull request and now we are back to master branch and here we see okay but this new head 20 so it disappeared with one commit came back with another one with one pull request from one branch came back and yeah I think that's all you have known for now I think that's a lot of stuff to know but these are some some of the basic things that you should know about there's a lot more to get than this but oh yeah let's see let's see one more thing okay so now I'm going to get check out master okay and I'm in master branch and I make some change so now I know just talk why I cannot make change your won't matter what you how to do that let me think I'll create a new branch hit check out - B - B for new if you don't have new then o - me that's three and I do nano testify so I'm going to do this part very quickly okay so one more thing now I forgot to poo so I don't have the latest changes from master and that's going to cause issues but I've already created a branch so I can just incorporate the latest changes from master check out master then I get pool then I move back to test three you check out test three get merge master so this time I didn't get any conflicts I got the latest changes so i do nano testify okay let's say I make it thirty get a.com it - them ready get push reach in just three so I got the three new port case was created and we then when we create a new protocol people approve or they can also comment if you want to change something and I emerge this one and now I go to get check out master okay now what I do is nano testify I haven't pulled yet and I move two hundred I don't know I'm just testing something locally and then I maybe I'm admin so I can push to master branch so what I do is I took it at dot and git commit - M I'd say okay no it's going to be 40 40 head okay get push boom it won't push because you have some changes in master branch are in remote that you didn't pull so it's telling you run git pull and then you can push so I won't get pulled and I have conflicts again and that's why you never make changes like this nano test start by and I'd say okay I keep let me go back let me go to this one current change and get and comment push okay yeah so sometimes it also gives you suggestions okay so now I'd push directly to master branch you should don't do that in when you work in an industry probably you won't even be allowed to do that and there's a lot more cool things that you can do with git and specially with github lot of cool things but I am NOT going to talk about them in this video since these are some of the basic commands that will help you so when you're starting with git and you can also use it to like to track your machine learning models and how to do that I'm going to come back to that in some another video but not this one this is going to be a huge foodie otherwise so it's seen a lot of people talking about okay how do you keep track of machine learning models you can do it using it very easy and now you have you have everything so when you can what you can also do is you can learn a bit more about kit so you learn as you face problems so you face problems with conflict you try to Google get conflict what to do you will get a lot of results there okay so I'm going to wrap up wrap this up now it's it's been a little bit longer than I thought and news get and start using it if you are not using it now and to keep track of your projects and everything and it's going to be very useful to you don't go and upload and download from get download zip or upload files don't don't do that but use get push get pull git commits use commits properly so make some significant change and then you commit that change okay so this commit describes this change and create branches when you're making improvements to your machine on models or improvement to the product and also yeah and tell me if I've done something wrong or if I can improve in some way and I would try to incorporate it in future videos but have fun and thank you very much for watching this video if you liked it then click on the like button and subscribe and share if you want you can show you one your friends to learn about get when they're working on projects with you so if somebody's asking you what is good you can or what this video to them ok then thank you very much and have a nice time see you bye bye
Info
Channel: Abhishek Thakur
Views: 9,040
Rating: 4.976789 out of 5
Keywords: machine learning, deep learning, artificial intelligence, abhishek thakur, git, github, scm
Id: kyL71RoNcCo
Channel Id: undefined
Length: 46min 28sec (2788 seconds)
Published: Wed May 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.