Git Tutorial Part 2: Vocab (Repo, Staging, Commit, Push, Pull)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this lesson we will continue to learn about git so we have two main goals in this lesson number one we want to grow our git vocabulary this just means we will learn about key terms and phrases that are used quite often and git and our other goal is to simply see get in action so I will share my screen and I will walk through a real-world example of using git alright so let's get started here on my desktop I have a folder named most advanced site it's a bit of a joke name all that it contains is a single HTML file a CSS folder with one CSS file ok so here's what that looks like in a web browser and let's imagine that the CEO of this amazing company and web site has asked us to remove this line of text that says single page and to make this header orange so in our text editor we would simply open up the HTML file we would delete that line of code that says single page in the CSS file maybe we'd add a rule that says target the h1 color orange save it refresh it alright so this is nothing new this is not exciting what we want to see is how git comes into the equation we know that git can track changes made to our project files so how do we make sure that the changes we just made get saved into gits history to answer that we're going to take a quick vocab a timeout ok so first off and get we don't call something a project we call it a repository or a repo a repository is where get saves all of the data all of the history all of the changes that it tracks for a particular project ok our next term is the working directory the working directory is simply the folder location on your computer where your project lives so in this case we had a folder on the desktop named most advanced site this is the working directory for this repository so gets job for this repo is to track any changes we make to any of the files within this folder okay so our next term is commits what is a commit well git doesn't save or store changes we make into its history until we actively commit those changes you can think of a commit as a secondary save right so in our text editor when we edit a file we save it we hit command S or ctrl s or we go to file save and that saves the files to our hard drive like normal but with git nothing gets saved and two gets history database until we make a commit now we will commit our changes in just a moment but first there's one last term we need to learn about and that term is staging in get before we are allowed to commit changes we first have to stage our changes so what does that mean well I like to think of real estate sometimes before you can sell a home you first have to stage the home staging just means getting something ready or preparing something now and get staging is our chance to have fine-grained control on what we are committing here's an example so let's say we are working on a larger project and we have made edits to twelve different files maybe we were experimenting and trying new things with code but we only want to commit four of those files into gets history maybe in the other eight files we made mistakes or we realized that those files weren't even necessary whatever the case the point is is that we don't always just want to push every change we've made into a commit so staging is our chance to say you know what hmm I don't want all of these I only want this file this file this file in this file those get moved into the staging area I take a second to review what I've staged I'm happy with it so I commit those staged files okay so now we've covered all of the terms that we needed to learn let's get back to sharing my screen and actually committing the changes we made to this page all right so in order to tell git which files I want to stage I'm going to need to do something that might seem a bit scary at first I'm going to open my terminal also known as the command line every computer whether you're running Windows or Mac or Linux has a command line the command line is simply a place where we can type commands now some of you are thinking is this really how we need to interact with git isn't there an app or a program that would make interacting with get easier well this lesson is neither the time nor place for that conversation in our next lesson I will try to convince you why using git from the command line is in your very very very best interest also in this lesson I don't want you to worry about trying to follow along step-by-step on your computer and I don't want you to worry about trying to memorize each individual little step in our next lesson I will help you install git on your computer I will help you find a command line on your computer and we can walk through all of these technical steps at a much slower pace together but in this lesson I want you to sit back a bit relax and just try to observe the general flow of what's going on don't worry about memorizing everything alright so first I want get to give me a recap of what I've changed lately so if I type git and then a new word status get status get lets me know that these are the two files that have been modified okay so I know that I want to stage both of those files okay so instead of having to pick which files I want to stage I can just say git add I want to add to the staging area get add - a this will add all changes to the staging area so now if I run git status again it tells us that okay here are your changes that are ready to be committed these are the files that I had in so this staging area looks good to me I'm ready to commit it so I just type git commit and it's always a good idea to include a message with your commit so I'll type - M and then a bit of a quote and I will say made the header orange and remove a line of text and we've successfully committed those changes into gets history the reason this is so nice is now even if in the middle of the night our cat sneaks onto our laptop and deletes all of our code and says hahaha cats rule and they erase our CSS file and just say purring and sitting in the Sun okay and we refresh and our hard work is gone all we need to do is come into our command line and type git checkout and our files are right back to the state that they were in when we made our last commit and even if your cat is especially evil and deletes your files out right in the middle of the night moves them to the trash and your cat is even intelligent enough to empty your trash and even close out your text editor git has still got us covered so we just go over to the command line get checkout the files are restored okay so now we know that the files in our repository are cat proof but are they disaster proof meaning if we accidentally threw our laptop into a pool of water or off the side of a cliff would we be able to still access the files let's answer that question right now in the final section of this lesson titled push and pull okay so get stores all of its history data in a hidden folder in the root of your git repository so for example in the project that we've been working on in this lesson this most advanced site folder get actually has a hidden system folder that we can't see right now and in that folder it stores all of the commits all of the changes all of the history for our repo get stores all of this locally meaning on your computer's hard drive now if all of this data is only on your hard drive that means a few things number one if your computer blows up your repository is completely lost and number two collaborating with a team of others is going to be pretty difficult considering only you have access to your computer now we can solve both of these issues by hosting our git repository on a server somewhere this is exactly what the popular service named github offers there's a good chance you've heard of github before really quickly I want to point out that git does not equal github github is just one of many many many services that can host your repositories github just happens to be the most popular service and it's also the one that we will be using throughout this course let's take our first super quick look at github right now so in a web browser I'm just going to go to github.com and then from there visit the particular repository or project that I want to work on so here is the super-advanced website you will remember that name from the one we were working on earlier so here's the github overview page for this repository you can see here are the files here's the index.html file that we edited earlier you can even preview the code in the browser but if we go back to the overview page and click on commits we can see here are all of the commits in this projects history and you will notice that the commits we made earlier in this lesson where we made the text orange and remove the line that's not showing up here in this list of commits and that's because we committed that to our local copy of the repository but now we need to take what's on our computer's hard drive we need to take that git repository and push it up to the server so I will jump back over to my command line and I'll just type git push origin master again don't worry about what I'm typing we will learn about this in the next les but for now I type that in and if we go back to github and refresh this page we see here is the commit that we worked on earlier and if I click it we can see the details github even tells us you changed two files and if we scroll down it even highlights in green the lines of code that we added and it highlights in red the line of code that we removed now the only thing that I want you to absolutely remember from the last minute is that what we just did is called a push we took the repository that was on our hard drive and we pushed it up to the server so now the server is up-to-date and has our latest changes okay so that's a push what is a pull well let's imagine that we go on vacation for a week and while we are gone our coworker makes a few updates to the websites code so a week later we get back from our vacation we go to github we click on commits and we see that there are two new commits from our co-worker named John Doe we can click on each commit and see what he did so in this commit he changed the heading to be about dogs and he changed all of the bullet points to be about dogs and in this other commit it looks like he just swapped out a few new colors now imagine that our boss asks us to remove the line of text about being very loyal well the files on our computer for the website don't even contain the word loyal because while we were on vacation our files don't automatically get updated from the server so what we need to do is pull in the latest changes from the server into our local repository so that we are working with the most updated files so we head to the command line and I'm going to pull the keyword here is pull don't worry about any of the other syntax for now but I'm just pulling in the latest changes from the server we can see that the poll was successful so if I go back to my web browser of my local copy of the site and I refresh we see the color changes that our co-worker made and we also see this line of text that says is very loyal so our boss wants us to remove that so in our text editor I'm just going to delete that line save it that looks good so now I want to stage that change so let's do a git status yep that's the only file that I want to add so I'm going to do add it to the staging area that looks good so we want to commit that get commit our message will be removed line about being loyal and then now that that's committed remember we want to push that to the server so git push origin master we will review this syntax in the next lesson so don't worry about that but we're pushing it okay now if we go back to github click on commits here's the change that we just made and that wraps up the basic git workflow that you would use on a daily basis let's review what we learned in this lesson we learned what a repository is we learned that nothing gets saved into gets history until we commit and we learned that before we can commit we have to stage our changes or stage our files and we also learned that working with a server involves pushing and pulling so we learned quite a bit now in our next lesson you will begin to get your hands dirty so I will help you install git on your computer and we will work on command-line basics this is where things start to get fun and I will see you in the next lesson thanks for watching this excerpt from my new get a developer job course I hope you feel like you learned something and if you'd like to check out the full video course there's a link to it in the description thanks again for tuning in and I'll see you in a new video next Tuesday
Info
Channel: LearnWebCode
Views: 96,570
Rating: 4.9738059 out of 5
Keywords: git, tutorial, command-line, repo, staging, commit, push, pull, command line
Id: n-p1RUmdl9M
Channel Id: undefined
Length: 15min 17sec (917 seconds)
Published: Thu Oct 20 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.