From the course: Git Essential Training (2023)
Git for version control
From the course: Git Essential Training (2023)
Git for version control
- Let's start by discussing why you would use Git and see what problems we're trying to solve. This chapter isn't so much about how the technical side of Git works, we're going to focus on the concepts. So one of the big reasons to use Git is for version control. Let's paint a scenario. So you are working with code, you have this on your local computer and you're working with a file called Code1, and you're making changes, and at one point you think, well, I want to keep track of the change 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 maybe you create a file called Code2, and you start working on that file, and 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 make Code3 or Code2b, because maybe those changes aren't that big. And I think this is a process most people will be familiar with, where you create Code3, and then at one point you think, okay, we're getting there, this is going to be Codefinal, there's just some small cleaning up to do, and then you create Codefinal2 and Codefinalfinal, and Codefinal, now really, this is the one. You can keep going for this for a long time. This is where Git can really help you. So let's move back to the scenario where we started with just one file. So we have Code1, and next to that, we now have Git. So in the button we are working in our file explorer, whether we are 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 where we would first create our version 2 and our version 3, 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. And we keep working in that file called Code1, we don't create a new one, because we have a backup with Git, and we can do this again and again. So when we do it like that, all those old versions are stored in Git and they get a code so we can move back to them. So we can see the whole history of our code, but still 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 extend this process, because we are now working on our local computer. And this means that while we have a complete version control, we do have a risk of something happening with our computer and us losing all the files that we had. Git can help you with that by using a Git provider. So what we do when we have a Git provider is we can take our complete version history that we also have locally, and make sure it's also stored somewhere in the cloud. So if something happens with your device, you still have your code and everything that you have worked on. Now this is a bit of a simplified view of what is actually happening. The important thing here is that you understand the concept.