Git: Push, Pull, Fetch, Clone (with live demo)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back again in the last tutorial we learned about committing the files today we learn about sending our changes as well as getting new changes from the remote server so we have our local system laptop or desktop where we are writing our code similarly you have some remote server github.com our mid worker comm so the process of sending our changes from our local machine to the remote machine is called push similarly the process of taking all the changes all the new changes which might have been done by other developers to our local system is called pull there are actually a few ways there is a command called it pulls and there is command called git fetch to get the changes or let's say if you want to make a copy of the code which is present on the remote server then we clone the report so we learn about these commands in detail in this tutorial so before even pushing the code we need to create a blank repo on the remote server we'll do that so if I this is my github account and I'll go and create a repository here we will be pushing whatever changes we have or whatever commits we had done in our last tutorial let me create a new website and is an optional I'll write my web my site and I'll make it public so and I'll lose and create repository so now I have created one blank repository on a github server if the link which is important is this URL this is the URL which will we will use to link our local report to the remote server the command for that is let me copy this up we can also read few of the commands which have given here like to create create a new repository on the command line so this is basically on our local server if we create a new repository and we want to add this origin and push the changes but since we have already created our repository we will be following these commands so I will go to my terminal let us go to our code base doing it status so nothing to commit now we need to add our remote to git remote add origin and we'll copy that link if you call type git remote again it will give me what remote I have added here so this keyword origin this is actually the name of the repository on the remote server which we are adding so because whenever we are pushing we need to specify to which repository we are pushing and remembering this whole URL is a little bit Messier because we won't be able to remember it that's why this acts as a kind of an alias so we can also add another remote let's say git remote and I can name it if we the repo exists on my bed Bukkit server but vit bitbucket and i can give the URL for that as well so form from my local system I can push changes to two different remote servers and I can add n number of remotes as here now since I have added to my remote let me push my changes get pushed - you poor region and master so this doesn't ask for that gate push - you then origin origin is basically the idea show this and then master here we need to give user name as well as password so that person is pushing the changes only to the authorized report to the repo which are created by him on so the username is add me and I will type on the password I forgot it's saying counting objects then doing something yeah and if you see here its branches in this and remote resolving and not everything since it has created a new branch on the remote server and the changes are pushed so I will go here and I'll just reload my page yeah so now we can see whatever files which we have added there all the files are coming here and if you see we have created five commits you can see here whatever commits we had added then there are some other things which we'll be discussing as we will go in the further in the tutorial now as we had done committed from our local system similarly we can do commit directly here here in the github.com as well if I go to the my website I can let's say open this home dot HTML and I can simply open it edit edit this file just to commit the changes so what what is the message which we wanted to type so added some additional text commit changes so we the changes and he commits the last commit message shows here so we have written some idea added some text which is coming here now so this is about push now let's try adding another remote so that we can push the changes there as well so let me go to the home and create another website folder you repository [Music] tests repo push and just create the repo so we got this URL so click coming back here then get remote hard and will rightly test the PO this so here you can see we have added two remotes one is a region which is our existing one another is tester which we have created right now we'll push the changes to this as well to verify if it works hearing this up get push - Cu test drop Oh master username password yeah it's done now we'll lay low and you see all the changes are coming here now going back to our original website here we have added an additional comment which is for the home dot HTML now this commit is done on the remote server which is directly on github.com but this commit is not present in our local system so this is where get pull or get fetch will come handy so if I come to my website I will do git pull origin master this will pull whatever changes have been done on the remote server and apply it on my local code so the syntax is can get pull then we have to specify the remote which is like origin or it could be tester for like we have created two and then branch name now let us add an another commit which is let us say we update our index dot HTML and here we'll I'll open right up my codebase now and we will see if the changes are here the change which we had done was we're going to index dot HTML yeah and we had added one title tag with liners have cat minutes present here similarly there is also a command called git fetch which also does the same same task the difference between get fetch and get foolish something like difference between downloading and applying the changes so get fetch downloads all our changes which are present in our remote website but it does not apply is it even if you do get fetch you you will be downloading the changes but the changes won't be seen here unless you do an another command which is get merged to apply the changes however git pull will actually download the changes and it will directly apply it we have already seen how grid pull works now let us try to see how git fetch works so for that I will go here and let's add few more compared one h3 tag slash h3 in commit and then changes are still not here so let's try to fetch that comment gate fetch region and it face neither changes do you see here where the ice tree tag which we have applied there is not coming here now we need to apply the changes or we need to basically March our code get merge origin slash master and now see the our changes are here so this is the difference between git fetch and get pull so fetch is generally a safer method because you can be sure that the low code written in the local won't be overridden in case there are some changes or somebody has modified the file which is present on the remote server so this is about git push to gate pull and gate fetch next we will see how to copy our repository which is the rent on remote server but not on our local system so the command for that is get to own so this is our side which you are working on and I will delete it up and it is deleted so if you see everything is deleted now so we need to clone the content which is present on the remote server but not in our local system so if you go in the gate github here is it saying a command for clone or download so we'll copy this URL and then in our terminal will simply type git clone and this file name should say including cloning into website yeah it's done now see the website folder is here and if we go here this is a great repository now if I do get log you can see that added is 3 tag in HTML index dot HTML which was our last commit so this is about git clone here just as a clarification the difference between clone fetch and pull is clone is when you don't have that a code base or repository in your local system so you are basically copying the entire repository then comes a pull and fetch when you already have the code then pull is basically when you copy the changes hand pull directly applies and applies in your system but fetches when it only downloads the changes but it does not apply that swab after you fetch it you have to apply those changes using the much come on think this will be enough further today's tutorial I hope you have understood all that lists all the four commands and in the next tutorial we learn about branching concepts I know we are only working on the master branch where we are doing all the post pull or whatever to the master grant but from the next tutorial we learn Lansing which is an awesome concept like so I hope you enjoyed watching this tutorial please make sure to like this and subscribe to my channel and till then take care bye bye
Info
Channel: Linus Academy
Views: 11,889
Rating: 4.5500002 out of 5
Keywords: git, git basics, push, pull, clone, fetch, git push, git pull, git clone, git fetch, git tutorial series, git tutorial playlist, git for beginners, git for beginner, learn git in easy steps, git tutorial, git playlist
Id: H63nJJhoiMw
Channel Id: undefined
Length: 13min 10sec (790 seconds)
Published: Mon Sep 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.