Configuring Git Settings3:03
set user.name is my own name, and then I'll do one more for my email address, jeffrey@lyricast.com. Now there's one other change we can make, or we could stick with the default. There are some instances when working with Git where it will load up a code editor. If you want to override the default, the default might be vim, or it might be something else. Well, in that case, you could say git config, once again, for global configuration, and I want the core editor to be whatever you want. If you want it to be vim, that's fine, or emacs, whatever you prefer. Or sublime, any of those would be fine. All right, let's continue on. Now, if I run Git, you'll see all of the various commands that we can run. Now, this is a little overwhelming, but I'm going to let you in on a little secret. The reality is, the huge majority of developers work and function just fine using 10% of Git's features. So for many of these commands here, I promise and guarantee
Focusing on Core Commands3:54
let you in on a little secret. The reality is, the huge majority of developers work and function just fine using 10% of Git's features. So for many of these commands here, I promise and guarantee you that a lot of developers working professionally don't even know how to use them. They know the basics. They know how to add and commit and push and pull. They may even know how to revert to commit or rebase. But beyond that, it's actually only a small percentage of developers who really learn everything there is to know. And that's really a testament to Git. 10% of its features will take you a really long way in your career. So to finish up this video, why don't we create our first commit. I'm just going to go through the process. And then in the next video, we'll break it down and figure out what exactly it means. Now, right now, I have an empty directory. I'm just going to echo hello world and save that to index.txt. And that's identical to just creating and
Version Control as Snapshots4:41
it down and figure out what exactly it means. Now, right now, I have an empty directory. I'm just going to echo hello world and save that to index.txt. And that's identical to just creating and saving a file and typing hello world. So now, if I run cat index.txt, we can spit out the contents of that file. So when it comes to version control, think of that as a way of taking a snapshot. If you ever worked back in the day before version control was ever a thing, you might have ended up in situations where you would just copy and paste your whole project folder and save it to a backup. That way, you have everything you want, you can still toy around with some other idea, and if that fails, well, rather than finding a way to just hold down command z for 30 minutes, you could just delete that and make a fresh copy of your backup. That's sort of a manual makeshift crappy version control. And a lot of us did that back in the day. You'd have folders that
you could just delete that and make a fresh copy of your backup. That's sort of a manual makeshift crappy version control. And a lot of us did that back in the day. You'd have folders that would say like project-date. And then the next day, project-new-date. And then project-complete. And then project-complete-for-real-this-time. You'd have all these backups just to protect yourself. Because if something happened to that current folder, whether you accidentally delete it, or you make changes that break everything and you can't undo anymore, you can always go back to that backup. Needless to say, though, there's a much better way and that's what tools like Git provide us. Okay, so let's imagine this is a project. We've been working a long time on that index.txt file, and I want to save it to version control. In other words, I want a snapshot of its current state, and I want to store that. Cool. Well, if I run git
Initializing a Repository6:13
working a long time on that index.txt file, and I want to save it to version control. In other words, I want a snapshot of its current state, and I want to store that. Cool. Well, if I run git, you'll see that we have this command right here, git init. Create a new Git repository. Think of this as the first command you run for a project. I'm ready to use git, so I will type git initialize. Notice that it creates this .git folder within the current project. You'll see it right there. Any commits or snapshots you save will be stored within this directory. But mostly, you don't really need to go into that directory. You can forget about it. Okay, so I have this one file, and I want to take a snapshot of it. So I will use git add. git add index.txt. Now, we'll talk about this more in the next video, but to start, well, you can think of git add almost like taking a photo of the file and the way it currently looks. Now, though, we haven't saved the file. We haven't stored it.
Staging and Committing Changes7:06
the next video, but to start, well, you can think of git add almost like taking a photo of the file and the way it currently looks. Now, though, we haven't saved the file. We haven't stored it. We've just taken a photo. And then later, once we've decided, yeah, this is good to go, let's create a backup. Well, that's sort of like what a commit is. So if I were to say git status, what is the current status of my project? And you'll see, well, you added one file to the staging area. And now, if we run git commit, this is where we can type a message for what we just did. And this is a good thing. Whenever you make a change that you could describe to another person, and this is especially true for bug fixes, you download their project, you make your changes, and then you commit it and say fix the bug where users were being billed twice or whatever. That can be your message. But now, what about like the initial things where you're just sort of getting everything
commit it and say fix the bug where users were being billed twice or whatever. That can be your message. But now, what about like the initial things where you're just sort of getting everything up and running? Well, often people will do something like this. For the very first commit, maybe if you install Laravel, you'd create a new commit, and you'd say install Laravel as the message. Or you'll see people say initial commit, or first commit, any of those are fine. Or you can run git commit -m, and you provide your message right here. That would be equivalent. And generally, that's what I do in real life. All right, so we have added a file to the staging area, and we've committed it. So if git add is sort of like taking a photo but not saving it, git commit is sort of like saying, okay, for all of those photos, save it and send it off for safekeeping. So if I were to say git log, give me a log of all of your commits, sure enough, you'll see our first commit.
Viewing Commit History8:41
like saying, okay, for all of those photos, save it and send it off for safekeeping. So if I were to say git log, give me a log of all of your commits, sure enough, you'll see our first commit.
