Transcript
  • Servers and Tools

Introduction: How Does Git Store Content?

From the class:  Inside Git

I've navigated here to the dot git folder of a source code project that I'm working on. And this is the Git database. This is how Git stores it's information under the hood. Don't be afraid. In this class, we're going to learn what all of these files and folders actually do, what they mean. And we're going to learn how Git works under the hood.

Why would we do that? It might seem strange that we're starting with a, quote, "advanced," unquote, topic. But the reason is it's not that complicated. And I think if you understand a couple of the core concepts of how Git works, the higher-level concepts and workflows will make a lot more sense. So instead of spending all this time memorizing commands, and workflows, and vocabulary that doesn't really make a lot of sense, you'll just look at a couple key things, and be like, oh, OK. This is what it's doing. I understand now.

I think that most people do the opposite. They end up memorizing vocabulary and commands, and you can actually do that for a really long time. You can use Git without understanding any of this stuff under the hood. But I think it's frustrating to do it that way because you're always kind of afraid. Am I messing things up? What's actually happening? If I do something wrong, how do I fix it? And then people all over the web are throwing around vocabulary that you probably don't understand. And that's just annoying.

So let's just get into it and figure out what these core couple of concepts are. Forget everything you know about Git. We're going to start at the very primitives and work our way up to the commands that you probably use all the time. So inside of this directory here, the first key concept that you need to understand about Git is that it's basically a database. It just stores key values. So it's a key value database.

And the keys are these weird 40-character strings that are called SHA-1 hashes. We're going to look in the next video at exactly what that is. And the value is going to be just some content, some file content. It could be a project, or a content of a file in our project. Or it could be a commit. It could be a bunch of other things. We'll look at all of those in upcoming videos.

So let's take a look at the Objects folder. That's where Git stores this stuff. And we can issue the find command into the Objects folder, and say, show me all the types, all the things in this folder that are of type file. And notice, it's just a big, long list of files. And so this is the actual Git database. It's storing a bunch of files where the file name is the key.

And notice, it's this for 40-character string here. This is the SHA-1 hash. That's the key. And the value for this file, in other words, the contents of the file, could be any of the different types of Git objects. One of those objects could be the content of our file. Another one could be a commit. And there's a few others that we'll take a look at.

So let's get you set up for this class. I put the prerequisites for the class down here. And I think the only one you're actually going to need is the shell. And that's even sort of optional. You just need it if any of the commands aren't making sense to you when I'm typing into the terminal. Go back and watch this class, and that should clear up any confusion.

Over in the materials section, you can grab the source code on GitHub if you want to take a look at the Git repository when we're done with it. Here's a bunch of keyboard shortcuts that should make your life a little bit easier. And as always, please share the content with your friends. That helps me to get new users. And I really appreciate that.

So if something really resonates with you, if you really enjoy it, go ahead and share it on Twitter, or Reddit, or one of these social mediums. All right, in the next video, let's jump into what is it a SHA-1 hash? That's the key technical concept you need to understand to understand how Git is storing stuff.