From the course: Git Essential Training
Git for version control
From the course: Git Essential Training
Git for version control
- [Instructor] Let's start by discussing why you would use Git and see what problems we're trying to solve. This chapter isn't about how the technical side of Git works. We are going to focus on the concepts. So one of the big reasons to use Git is for version control. Let's think of a scenario. You are working with code. You have this on your local computer and you're working with a file called Code1. You're making changes and at one point you think, "Well, I want to keep track of the changes that I just made." I want to try something different, but keep this file as sort of a backup in case I make changes that don't work out. So you create a copy of the file and you call it Code2. You start working on that file and Code1 is still there as a backup. After a while, you might reach that point again where you think, I want to make some big changes and I want to make sure that I can go back to this version of the code. So you might create a new copy called Code2b because the changes weren't that big this time. And you keep working and you keep making new versions. Now, at some point you will think, okay, we're getting there. This is going to be Codefinal where there's just some small cleaning up to do, but then you discover that you need to make another big change. So you create Codefinal2 and then Codefinal final and Codefinal now really this is the one. You can keep doing this for a long time. Sounds familiar? This is where Git can help you. So let's move back to the scenario where we started, which is one file, the file Code1, but now we also have Git. So in this image, we are working in our file explorer at the bottom. Whether we're on Windows or Linux or Mac, this is where our files are stored, and we install Git, which is a separate piece of software on our machine. So in a first scenario, we would create version two and version three. Instead of that, when we come to a point where we think we want to keep track of the code as it is at this point, we create a version in Git. We call this a commit. So we commit to Git and say we want to keep track of this specific version. We now can keep working in that file called Code1. We don't create a new one because we already have a backup with Git and we can do this again and again. So when we do it like this, all those old versions are stored in Git. Through Git, we are able to move back to old versions and see the whole history of our code. And the good thing is we keep working in our single file, so we know we'll never be working in the wrong version and our file explorer doesn't get messy like it would before. And we can even extend this process because we are now working on our local computer. And this means that while we have complete version control, we do have a risk of something happening with our computer and us losing all the files that we had. We can solve this problem by using a Git provider. This is some sort of cloud source that is specifically made for Git like GitHub. We can now take a complete version history that we have locally and make sure that it's also stored somewhere in the cloud. So if something happens with our device, we still have our code and everything that we've worked on.