What is Git?

A free video tutorial from Brad Schiff
Web Developer
Rating: 4.7 out of 5Instructor rating
9 courses
246,539 students
What is Git?

Learn more from the full course

Git a Web Developer Job: Mastering the Modern Workflow

Learn Git, GitHub, Node.js, NPM, Object-oriented JavaScript, ES6, webpack, Netlify, BEM and Job Interview Tips

15:34:39 of on-demand video • Updated June 2023

Build websites using the modern skills, tools, and best-practices that companies are looking for in developers.
Write organized, well structured JavaScript and CSS that other developers can easily understand.
Confidently apply for web developer jobs knowing you can jump into a dev team and immediately contribute to projects.
English [Auto]
Hello everyone. In this section of the course we will learn about Git. Let's begin with a few questions. So in this first lesson, here is what we are going to answer together. Number one, what is git? Number two, why should we learn git? And number three, where do we begin? So we are going to answer all three of these one by one. Let's begin with what is git? Git is the world's most popular version control system, but that phrase is just empty words. So instead, let's talk about what does git do? Why is git so useful and why do so many people love git? So really git just helps us manage our projects files. Now a project could be anything. Let's imagine that we are building a website so our project would have all kinds of files. It would have HTML files, CSS files, JavaScript files, images. You get the idea. You've got a whole lot of files. Now the question becomes what does Git do that makes managing our files easier? And the biggest one that I want to talk about first is history. So history just means that Git keeps track of every change we make to our project. Here's an example of why that's amazing. Let's imagine that we adjust the CSS on a website. Maybe we delete a few styles and add a few new styles. We think that everything's great, but a month later we discover that our code changes. Broke the layout on a few pages. Now, instead of scratching our heads and trying to remember what code we adjusted a month ago and involving a bit of guesswork instead, we can have Git tell us exactly on which day we changed which files and it will even show us which lines of code we added and which lines of code we removed. So this is great. This means you can rest a little easier at night now knowing that git has got your back, if you need to revert changes, you can. If you want to look back and see how a file has evolved over the past year, you can. Nothing is ever lost or nothing is ever final thanks to Git's history. Okay, so let's move on to the next reason that people love Git and that is collaboration. Now, if you've ever tried to create something on the computer with a group of people or a team of people, you know that a common concern is trying to avoid accidentally deleting or overwriting each other's progress. To illustrate this, let's look at collaboration without Git in the picture. So a quick example would be let's imagine we're writing a book and we finished the first one and a half chapters and we send an email to our friend with a word processing file attached and we say, Hey buddy, here's the first chapter and a half. Do you mind maybe making a few edits and finishing the second chapter for me and then sending the attachment back to me? Now, the moment you send that email, you are frozen, you are stuck. You can no longer work on the book yourself until your friend emails you back with the updated book file. Why? Why is that? Well, it's because you want to make sure that you aren't stepping on each other's toes. So let's imagine that you did make a few edits right after sending that email. What if you edited the first paragraph and maybe fixed a few typos in the last paragraph? Well, that would mean that your friend then wasn't working with the most updated copy of the book. So then when they send the file back to you, both of your copies are out of date, so you would almost have to ask your friend to manually step by step, summarize what exactly they changed. You'd have to say, Hey buddy, can you list out the specific changes you made so I can kind of replay those changes to my updated copy? And when you do that, your friend will probably reply by saying, No, I will not do that for you. Get lost, right? Your friend will be frustrated. They don't want to go through and recap every single change they made. And you're frustrated because now you would have to go through both files word by word and sort of compare them and see what change in either copy and mushed them together yourself. So no matter how it's sliced, one of you is going to have to do a bit of tedious, miserable work of sort of combing through things and merging them together. Now that process of tracking the changes and comparing and merging is exactly what Git does for us. So that example was just a long winded way of saying that Git makes collaboration very easy and it allows you to be more productive when working in a team. You don't need to sit around waiting for someone else to make their changes. You can continue working on your changes and rest assured that when it comes time to sort of merge everyone's changes together so that everyone has the most updated copy of the files. Git has got your back. Git will take care of merging any conflicts. Git will save the day. Now let's cover one final reason why I think people love git so much and that is something called feature branches. Okay, so what in the world is a feature branch? What does that mean? What is a branch? Well, the best way to explain that is to look at an example. So let's imagine that we have an existing website that we are responsible for editing and updating and making improvements to. And let's imagine that we were just assigned two tasks. Number one, we need to redesign the header of the website, maybe add a new logo, change the slogan, change the colors and task number two, we need to adjust the styling and ordering of the links in the footer. Okay, so how would things play out if we were not using Git? It would probably look something like this. Day one. We get started on both tasks, but we don't complete either task so we can't go live with our changes. Day two rolls around and we continue working on both tasks. By the end of the day we actually finish. The footer changes, but our header is nowhere near complete. So now we are in this weird position where we wish we could go live with the updated footer, but we can't because our code is all lumped together. And if we uploaded the files to the live website right now, the footer would look great, but the header would look broken and we might not finish the header for another week. Okay. And you never want one piece of your code holding another piece of your code hostage. So clearly this is not the most productive or efficient workflow. Now instead, let's look at the git way of doing things, the git way of implementing multiple tasks or features. All right. If we were using Git and we were just assigned the header and footer tasks, here's how it would look. Let's think of our project as a tree. We want to create two new branches, one for each task. So we'd create one branch and name it header changes and we would create another new branch and name it. Footer changes When we feel like working on the header, we check out the header changes branch. When we make any changes related to the footer, we check out the footer changes branch. We can hop back and forth between these two branches or between these two versions of our project throughout the day. Git tracks the branches separately from one another, so it is not a big deal if we finish one feature first. So let's say we finish the footer changes and we are ready to go live with them. All we do is we take that branch, that footer changes branch and we just fold it back up into our tree or we merge it into the tree. Maybe a week later or even a month later we finish the header redesign. Whenever that time comes, we just fold that branch back up into the tree as well. And that is feature branches in a nutshell. Okay, so we've answered the question what is git? We know that git helps us manage our files. Git basically tracks changes which does three big things for us. It gives us history, it makes it easy to collaborate with other people and it makes it easy to work on multiple features at once. Moving on to the next question. Why should we learn git? I can't think of a single reason not to learn git. Every job I've had in the last five years, I've used git every single day in the developer world. It's just sort of assumed that you know, git. So whether you want to become more attractive to employers or you want to fly solo but bring a bit of structure and organization to your code, learning Git is truly a must. Which brings us to where do we begin? Well, the good news is you've already begun. You've made it through this lesson. Which means you know what git is in the first place and what it does for us. The next step is to see Git in action. And that is exactly what we are going to do. In the next lesson, I will share my screen. I will walk through the basic steps of actually quote, using git. We can see some of its features come to life. We can get our feet wet together. It's going to be a lot of fun. And I will see you in the next lesson.