Git Tutorial 4: Basic Commands: add, commit, push

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends in this tutorial we are going to learn some basic gate commands so if you have already taken my gate tutorial on what is version control system and what is github you should already be familiar with some of the basic concept of version control system in this tutorial we are going to create a new github repository and we are going to add some code or while learning the basic git commands so to create a github repository first of all you need to go to github.com and you need to create an account I already have an account so I am law already logged in as a loan P user into github comm so I already have one repository called py I am going to create a new repository I am just going to call it test taste repository and by default with a free account your repository need to be a public if you want to make a private repo so that no one else can see it then that option comes under a paid account so I'm just going to make a public repository which anyone can see I'm also going to initialize it with a readme file typically when you write any code you always have readme file explaining what that code is about so I'm just going to add that when I click on create repository button it is creating an empty repository me a repository or with a readme dot MD file so if you open this file it just tastes repo if you want to edit it you can edit it in say test repo for git commands demonstration and if you commit it will come at it okay now github.com is a cloud storage it is a remote server so I already created a new repository how do I sync that up to my local computer for this you need to have a git bash installed so if you type in and get bash here if you click on it you will get this now I already have a tutorial on how to install git so when installed basically a good you get this get best installed so you can open it up on now I am in C code directory here what I'm going to do is are just clone this repository cloning the repository me means copying repository from github to your local computer so for cloning you go here clone and just copy this link so if you click here it's going to copy this link and then the first command that we are going to type is git clone and then you will copy paste the repository URL when you do that it is just cloning it on your local computer so when I do now LS I will see that now I have this taste directory here so I will go into test directory let me just clear this out and when I do LS I got a readme file so that's the only file we have okay now the command that you will use often with git is git status when you do git status it is showing that you don't have any changes in your repository it's totally empty and clean okay now we are going to add our first python file so let's open py charm editor here and here I have ah see code test directory open so I'm adding a new Python file and we are going to make a program called hungry so here in this program you are basically asking if you are hungry or not and you get some responses so just a simple fun program so the first line I will write here is I am hungry okay and usually when you write code you create a new file you write code you execute it you make sure it works okay yes it is me working okay it is printing whatever it is supposed to print and then you add your file to your version control system so now I have my code ready let me go back to git bash here and here I'm going to say get status when I do get status I get these two file dot ID or hungry dot idea is a directory that is created by py chump so you can just ignore it but here it says that git add file name to include what will be committed so in get whenever you are adding a new file you need to add it to something called a staging area staging area is the area or which contains the files that you are ready to commit commit means ready to push to your version control system okay so I will say my second command is git add hungry dot py so when you run this command what happens is now if you run git status this file now shows as green which means it is in my staging area now whenever I I've earned the next c'mon called git commit so git commit is now taking the files from staging area which means these files it will not take this file this directory and it will just commit it locally okay so now git commit command takes minus M as an option and M means a message so I'm just saying first version of hungry code okay so when you say get commit now you have committed your change into your local version control system remember when you run git commit comma command R you are not still pushing it to github which is your remote cloud the core still resides on your local computer git status okay so okay so it is in local version control database it is not still on a remote server server so if you run now the next command that you want to learn is git log git log will show you the log of all your commit history so when you say git log you'll see first version of hungry code and this is the commit ID oh and these are the two initial commits okay now let me clear the console so when Evan get status here now I don't have anything in my staging area whatever changes I made they are committed okay so the first just to revise the points are the first thing was git add that adds files to staging area next thing is git commit that commits your code to local version control database okay now the third command is now I'm ready to push my code to github so you just run git push o so git push will now push my code to my github so let me check what happened on github so this is my github repo I only see readme dot MD file now let me just refresh it so once i refresh it ah-ha here I see the new file hungry dot py so if you open it to see what our code I wrote now it is on the cloud so that now if I log in from some other machine or some remote place I can still get this code back I don't have to rely on my local computer to access this code alright or so now here in the if you click on this it will show you the commit log so our history is we basically created the empty repository then we added read me dot MD file and then we added our first of Python file hungry dot py ok so uh now what I'm going to do is I'm going to make some more changes into my Python file ok so I will say my hungry flag is are you hungry so my program is now asking question if you are hungry or not and if you are hungry I will say and eat samosa samosa is a very delicious Indian food it's fired it's not healthy but you can't resist to eat that because of its taste now if you only ate some also if you are not hungry then do your homework ok I'm going to run this program just to make sure it works ok ok when you say yes it is saying eat samosa when you say no it is saying do your homework alright my code is now ready ah so the next thing you do is you already have a file so again you'll be running git status come on a lot so I'm seeing again hungry dot py is modified so I need to add to my staging area okay and when I do get status it says it is in the staging area green means it is in the staging area now I will run git diff tool so git diff tool is a command that allows you to see the difference between whatever code you have previously versus whatever code you have right now okay so you would say git diff tool head will go or a concept of head later on but just for the simplicity you just run this command and it allows you to see the difference between your previous version of the file and the current version when I do this it's going to open this diff so here previously I had this is my previous file this is my new file so previously I had just one print statement and now I have this whole core okay so you just see the difference you make sure things looks okay and then what you do is you are going to get push oh sorry we missed git commit actually so we'll say git commit are added hungry prompt so you write a meaningful message or to mention what that change is about okay so once you committed you are ready to push and when you push it it will go again upstream so again let me refresh so I click on refresh button now instead of three commits I have four commits if I click here it will show my latest commit you know it says committed 20 seconds ago okay now it if on the github or website if I want to see the difference you just click on this commit ID and when you do that it will show you the difference see red means you remove this line green means you added this line okay so that was a quick demonstration of our three basic commands get add git commit git push now let me show you in a picture how that actually worked so if you look at this picture here what happened is our locally on my computer I had this working copy which is my local code and whenever I do git add it moves that code into a thing called a staging area staging area means whenever you do git commit whatever is in staging area will be committed and whatever is not in the staging area will not be committed so if you recall we had a directory called dot idea I never added that using git add come on that's why it never got pushed to github okay so remember you have to always do git add so when you do get add you are adding into a staging area next step is once you are sure you are ready to commit you should get commit come on when you do that it pushes those changes into a version database now this version database is present on local computer or this whole box is your local computer so or you are still not pushing it to remote okay so that's that benefit of using git it is a distributed version control system which means it allows you to track changes locally in your computer as well as on remote okay so once you have once you do get commit it will create version one then you will again make changes do git add git commit it will create another version version to again make changes look it add git commit version three so you will just keep on accumulating your changes in your local version database okay and whenever you are ready to push the changes to remove github repository you will issue get push command and once you do that as you have your code in the remote now once it is in the cloud you can you don't need to rely on your local computer you can access that code from any area of the world as long as you have internet connection okay so the basic difference between gate and other version control systems such as SVN is that SVN doesn't have this particular box in s3 and all you do is you make your changes and directly push to remote versus having this allows you to track your changes locally you know it's very powerful actually and that's the reason why I get is very popular nowadays alright so that was all about these three basic commands now the reason why I'm using command prompt is that command prompt allows you are greater flexibility there are many tools or many IDE is available from where you can push get come on get cold you can basically push code to get and do whatever things we did here you can do the similar things from that graphical user interface but I personally like a command-line interface because it is very very powerful very very flex flexible as well okay so in the beginning you may feel like you're to type lot of command but it's not that hard so just stay patient and it should just work out okay so always use command prompt I highly recommend it okay so that was all about gets basic commands or will learn a few more commands in the next tutorial thanks for watching
Info
Channel: codebasics
Views: 272,557
Rating: 4.8686972 out of 5
Keywords: github tutorial, git add, git push, git commit, git difftool, git concepts, git commit and push, git commit message, git commit tutorial, git push tutorial, git add tutorial, git commit command line, git push to github, git push to remote, git add file, git add commit, github commit, github push, git commands tutorial, git tutorial, git commands with examples, git bash commands, git commands, how to commit code in github, github commands, git basic commands
Id: eL_0Ok_Gkas
Channel Id: undefined
Length: 16min 35sec (995 seconds)
Published: Sun Jul 31 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.