Latest / Talk Python To Me / #311: Get inside the .git folder
Transcript
- 0:00These days, Git is synonymous with source control itself.
- 0:02Rare are the current debates of whether to use Git versus SVN versus some fossil like
- 0:08SourceSafe versus you name it, but do you know how Git works? What about its internals?
- 0:12I'm sure you've seen a .git folder in your project's root, but to most folks, that's a black
- 0:18box. In this episode, you'll meet Rob Richardson. He's going to pop the lid on that black box as we
- 0:23dive into Git internals and the .git folder, among other things about source control.
- 0:27This is Talk Python To Me, episode 311, recorded April 1st, 2021.
- 0:32Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:51ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where
- 0:55I'm at mkennedy, and keep up with the show and listen to past episodes at talkpython.fm,
- 1:00and follow the show on Twitter via at Talk Python. Congratulations to Mike Manning. He's the final
- 1:06winner of our PyCon ticket giveaway. Thank you to everyone who entered, and if you didn't win,
- 1:10I hope you're able to get a ticket and support the PSF, the Python community, and be part of that
- 1:15awesome conference. See you in May. Rob, welcome to Talk Python To Me.
- 1:20So glad to be here. I'm really excited that I get to join you. Great to meet your audience.
- 1:24Yeah, it's great to have you here. You got to meet Intersection. You gave a talk at the Python
- 1:29web conference recently that I also spoke at, and your talk was really interesting and certainly
- 1:35relevant to the Python folks, so I thought it'd be cool to have you over here. And, you know,
- 1:39I should give credit to Paul Everitt for connecting us. He's like, oh, that was a great talk. You should
- 1:43go talk to Rob. So thanks, Paul, as well, who was not long ago on the show.
- 1:46Yeah. I've been chatting with Paul about thoughts around the talk as well. He's a really brilliant
- 1:51guy.
- 1:51Yeah, he is. He definitely is. He's been doing a lot of cool stuff for a long time. So yeah,
- 1:55he's a great guy. Now, before we get into Git and all those types of things, which, you know,
- 2:02it's really surprising to me how much it's taken over the world, right? It used to be,
- 2:05there was always a question, well, what source control do you use? Like, that's not a question
- 2:09I hear all that often these days, not at least as much as it used to be. But before we dive into the
- 2:14details of that, let's start with your story. How'd you get into programming?
- 2:16This is actually a really fun story. I was 10. I was at the library because they had the computer
- 2:22and we'd play video games. And the methodology of how you do this is you go up to the counter and you
- 2:28flip through the book and you go find the video game and you show them that page and they give you the
- 2:34disc and you have the save icon. You take the save icon and you put it in the computer and you play the
- 2:39game. So I had finished playing my game and I went back to the desk to go pick another
- 2:44one flipping through the, you know, plastic sheets. And I found a drawing program. And I said,
- 2:50I'd like to play this game. They gave me an eight and a half by 11 sheet of paper. The top two thirds
- 2:55was graph paper, you know, graphs. And the bottom third was how to write the program to draw that on
- 3:03screen. Oh, cool. Okay.
- 3:05And it was so much fun. I got to start to build content that was in my mind in real life in this
- 3:13artistic medium with a very technical implementation. So, you know, that was so much fun. I did never
- 3:20return that game. And so that kind of brought me into the world of software development. I always
- 3:26thought it was just a fun thing that people did. I didn't realize it was a career. So it wasn't until
- 3:30really late in my college experience when I realized that I could do this for a career.
- 3:36And so after I graduated, I got into programming professionally and I've had a really fun time
- 3:42coding now for professionally for more than 20 years.
- 3:45Yeah. Awesome. I think programming is special because it's one of those things you kind of
- 3:50hinted at where you, you think of something, you dream of something, you imagine something.
- 3:53And then with a little bit more thinking, that thing can become real. Whereas, you know, so much
- 3:59of what humans do, it's one or the other. I could tell an amazing story and write the book,
- 4:04or I could go build an awesome house. But normally those things don't actually coexist where you think
- 4:10a lot about something and they come into existence. But I do think that's a magical part of what we get
- 4:15to do. And I think it captures a lot of people's imagination.
- 4:18And what's really cool is that in this digital world, there are a lot less boundaries, a lot
- 4:23less constraints. There's nothing telling me that this pixel needs to be in this certain way.
- 4:27I can draw whatever I want on these pixels on the screen.
- 4:30Yeah. Yeah. And modern day, we have cloud computing and we have incredible computers. Like
- 4:35the sky's the limit. It's really, really awesome. Also money. You don't have to go buy tons of hardware
- 4:41for many things that we do. Right. So really cool. Now, how about today? What are you up to these days?
- 4:46I'm doing a lot with software development, cloud-based development, a lot of websites,
- 4:51a lot of web properties, ASP.net and Node on the backend, React and Vue on the front end.
- 4:57Taking that into interesting modalities, I've started to play with Raspberry Pis and that's
- 5:01really fun. And getting to dig into all the things. I've gotten really good at doing DevOps as well.
- 5:07Part of my passion is being able to share this knowledge with others. So I do a lot with teaching
- 5:13both at user groups and conferences and elsewhere mentoring. And so it's really fun to be able to
- 5:19not only learn these new skills, but also pass it on to the next generation of developers too.
- 5:24I love to say that it's not that I'm really good at it. It's just that I've been collecting things for a
- 5:30while. So let me add to your collection too.
- 5:33Well, I think one of the things that's really interesting about becoming an expert in programming,
- 5:37people who are beginners or maybe don't do programming at all, they see that person as
- 5:42incredibly talented and incredibly smart. And they may be, they often are, but I feel like the real
- 5:49big difference is I've spent 10 years gathering up these little tips. Like, oh, I tried this.
- 5:54That doesn't work very well. That crashes. You try to talk to the database that way. That's bad. Oh,
- 5:58by the way, I've also built up a couple of examples of what databases are. And I've seen,
- 6:02you just have this almost more experience than, I don't know, like innate skill, right? So it's
- 6:11really cool. You can just kind of layer on these skills over your career. And the reason I think
- 6:15that's powerful is it's, they're very easy to communicate back to other people, right? If,
- 6:19you know, the way Nietzsche did philosophy or the way Euler did math, like you can't, or Bach did music,
- 6:28like you can't easily communicate that to someone. Like if it's this crazy innate skill,
- 6:33you can sort of communicate it, but it's not the same. But with programming, I think it's very easy
- 6:38to transmit it on and pass it on and ways to help people like level up. It's super fun.
- 6:42And it's really easy to get started. You know, programming languages have become much more
- 6:46approachable of late. And so if you're new to programming and just starting to dabble in it,
- 6:52you don't need to buy a big expensive thing. You know, the laptop that you're using to browse the
- 6:56web is probably sufficient for building simple programs. And so, you know, dive in,
- 7:02use free tools and just start building stuff. It's really approachable and really fun.
- 7:08It absolutely is. And one of the things that just never ceases to blow my mind is I can be in a coffee
- 7:13shop working on a relatively cheap laptop doing my coding. Git push, speaking of Git, something happens
- 7:20on one part of the cloud. It triggers a webhook somewhere else that then grabs the code and could run
- 7:25that on a tremendously powerful data center and computer or suite of computers, a cluster of
- 7:31computers. And yet I get the experience of basically building this super powerful thing on my very wimpy
- 7:36little laptop. It's just cool that you can create things like Facebook or Google, or you name these,
- 7:43these really large, amazing apps, but you could kind of just do it on like a laptop.
- 7:47Something that existed in my mind yesterday exists in the cloud and scaled to any user that wants it
- 7:56tomorrow. Yeah. That is really fun.
- 7:58Yeah. It's super, super fun. Before we move on, you also mentioned that you've been playing around with
- 8:03Raspberry Pi.
- 8:04So, something that I covered recently on Python Bytes, my other podcast, is somebody built a water-cooled
- 8:11Raspberry Pi cluster computer. So, eight Raspberry Pis in one thing, all of them overclocked and water-cooled.
- 8:20Have you seen people doing this stuff? It's crazy.
- 8:22It's really cool. And as you start to get into clustering programming, clustered programming, you know,
- 8:27multi-machine type of experiences, a Raspberry Pi is a really cheap barrier to entry. You know, for $40 or so,
- 8:34you can get a Raspberry Pi, get three or four or five of them, cluster them together, and now you get the sense of
- 8:41what does it take to build parallel machinery. And it is really, really fun. So, you know, to get an eight or ten or a hundred or a thousand,
- 8:51node Raspberry Pi is pretty sweet.
- 8:55Yeah, that's awesome. I mean, you can do something similar with Docker, right? Fire up a bunch of Docker containers, but it's not the same
- 9:01feeling as like, there's actually eight of them over there, and they're actually talking to each other and working together. I think it's a very
- 9:06different feeling. It's super cool.
- 9:08Containers do help us start to approximate that. But yeah, there is some lying to ourselves to believe that all of these containers running in context on my one laptop are really a
- 9:19distributed system. Yeah, absolutely. It's not the same, but it does let you sort of play around there a bit. Right. All right. So I want to talk about Git
- 9:26primarily, and that's what your presentation at the Python web conference was about. And that's what we're going to center our conversation on. But you know, you and I have both been around the
- 9:35industry for a lot of different things.
- 9:38Yeah.
- 9:38So maybe let's talk a little bit about the history of source control. You know, I think of source control as a spectrum from what source control all the way to get and distributed source control. Maybe, you know, there's, I've talked to people and I've seen it in action. Source control is I've got a file code file,
- 10:01and I've called it version one version two version two edited version three version three final final two, you know, just like, or maybe if it's a lot of files, you zip the folder and you name it like that. Right. Like that's the beginning of source control. He's doing it wrong, but it's getting getting there. Right.
- 10:18Well, it's doing it in exactly the way that you needed at that time. Copy folder versioning is definitely a thing. Dot bu dot date, you know, copy that content off to make sure that you have it. And that's really what we're after with version control is when we think of version control, we're really talking about two things.
- 10:38One is archiving the history of my journey so that I can get back to a known good state if things go bad, but also communicating with my team to be able to convey the progress of this system.
- 10:52Yeah.
- 10:52And copy folder versioning does the first one real well. It doesn't do the second one real well. There are systems that I've worked on where, you know, to upgrade the system is to first copy all the things into the dot backup folder and then upgrade the primary thing. And if it doesn't work correctly, then you point the...
- 11:11Put it back, put it back, put it back, put it back.
- 11:12Yeah. They point the web server at the backup folder. And so now the system has been running out of the backup folder for, you know, six or eight months or a year. And now we go to upgrade and step one is to take, oh, wait, we just took down the site. Now we have no known good backup thing.
- 11:30Yeah. Without some sort of source control, the real thing I think that falls apart, maybe you're doing the file versioning thing, which is still not that ideal, but the thing that really falls apart is collaboration.
- 11:40Right. Soon as two people want to work on something, it's not okay to say, well, here's my zip version. Can you merge that back together? And probably you don't have merge tools either. So what does that even mean? Right.
- 11:49So I quickly gets us into where I think people probably should be in some sort of version control, but back in the day, that was different stuff. For example, you know, maybe that was subversion. Actually, if you were on subversion, you were in a good place. I mean, a really good place.
- 12:06Yeah. Subversion was really cool. Subversion was an upgrade to CVS where CVS would version each file or each folder separately. And so nested folders just happened to kind of be together in this clump.
- 12:21And what subversion gave us was we're versioning the entire project together in one piece. Before that, we might've had source safe or other pieces. Team foundation server kind of fits into this realm as well.
- 12:35And so it's that mechanism of versioning all of the pieces together and then being able to publish that to a central place. What makes all of these systems kind of unique, specific is that they're all really client server pieces.
- 12:49So version was really good at being a client server piece.
- 12:53I'm going to go out on a limb and say it was the best client server version control system that I'm aware of.
- 12:59Yeah.
- 12:59I think so.
- 13:00These systems though, kind of a fundamental flaw because we want to use version control for those two pieces.
- 13:06We want to use it to be able to back up the work so that I can get back to a known good state and to communicate with our team.
- 13:14And the hard part with these client server version control systems is we're doing both every time we commit.
- 13:22So when I commit a change to subversion, I'm immediately publishing it to all of you.
- 13:28So the analogy that I like is when I'm rock climbing, I want to be able to put a carabiner in the wall as frequently as possible.
- 13:38If I climb a foot and I fall, I'm only going to fall a foot.
- 13:42If I climb six or eight or 12 feet and I fall, I'm going to fall 12 feet.
- 13:47Well, actually the nature of the rope is that it's going to swing all the way down.
- 13:50So I fall 24 feet and that's a long way to go.
- 13:54I want to stick pieces in the wall as frequently as I can.
- 13:58You don't want to see me spamming the thing every time I get there.
- 14:03So I get to the point where it's like, okay, I finished the thought.
- 14:06I'm good.
- 14:07I want to mark this save point, but I'm not ready to publish it to all of you.
- 14:11Yeah, because really the thing you should be working with most of the time is if I publish it to the rest of the team, it should be, it should at least run.
- 14:20Right.
- 14:21Yeah.
- 14:21Probably the test should pass.
- 14:22Maybe you can fix that.
- 14:24Like you're going to work with somebody, but it shouldn't just mean nobody can build or even start the software at all.
- 14:31Because you've got the save point in the middle of their work that is inconsistent or halfway there or whatever.
- 14:37Right.
- 14:37And so I've reached the stopping point, but I'm not done.
- 14:39It doesn't work.
- 14:41And so I have this moral dilemma.
- 14:42Do I mark a save point and inflict that on all of you or do I not?
- 14:47And that's when I fall back to a secondary version control system where I start doing copy folder versioning again, where it's like, I just want to take all my stuff and stick it in this spot so that I have this known good state.
- 14:59And that's where we pivot to distributed version control systems of which Git is one of them, where we have a separation between the commit stage and the publish stage.
- 15:10And that isn't the official terms that Git or any of the rest of them use, but there's a process of marking those save points.
- 15:18And then there's a process of collecting all of the save points and publishing them to others.
- 15:23It takes a bit of a mind shift to get used to it as well when you're working on it, because if you come from one of these other systems, I committed, so it's saved.
- 15:29Right.
- 15:30But commit in a distributed source control system means it's a local save point until you Git push or whatever other immacterial's equivalent of a Git push is.
- 15:41Right.
- 15:41Yeah.
- 15:41An HG push.
- 15:42And so it's exactly that.
- 15:44It's marking save points however frequently you want and then combining those save points together into a cohesive story.
- 15:52To publish to your colleagues.
- 15:54And that's what makes distributed version control so powerful is separating those two concepts.
- 16:00Mercurial, Git, Perforce.
- 16:03There are other distributed version control systems.
- 16:06And as the world was moving from subversion and TFS into this distributed world, we experimented with each of them.
- 16:14You know, arguably Git wasn't the best.
- 16:17We might have done a VHS and Betamax type of thing.
- 16:21But clearly Git has become the de facto standard version control system.
- 16:26It is distributed.
- 16:27And now we can separate the save points from the publish points.
- 16:31Talk Python To Me is partially supported by our training courses.
- 16:35At Talk Python, we run a bunch of web apps and web APIs.
- 16:39These power the training courses as well as the mobile apps on iOS and Android.
- 16:43If I had to build these from scratch again today, there's no doubt which framework I would use.
- 16:48It's FastAPI.
- 16:49To me, FastAPI is the embodiment of modern Python and modern APIs.
- 16:54You have beautiful usage of type annotations.
- 16:56You have model binding and validation with Pydantic.
- 16:59And you have first class async and await support.
- 17:02If you're building or rebuilding a web app, you owe it to yourself to check out our course, Modern APIs with FastAPI over at Talk Python Training.
- 17:10It'll take you from curious to production with FastAPI.
- 17:14To learn more and get started today, just visit talkpython.fm/FastAPI or email us at sales at talkpython.fm.
- 17:23I think another really important thing to highlight for people who haven't been there, right at the Git homepage, they highlight Subversion, which we've been talking about.
- 17:34But Perforce, ClearCase, SourceSafe, TFS, a lot of these things, there's two things.
- 17:40One, they would lock files.
- 17:42Like if you wanted to make a change to a file, you would claim it.
- 17:45Like I'm editing main.py, well, no one else can interact with that file.
- 17:51It's literally made read-only on your computer until, you know, until that person is done.
- 17:56And they had better not forget and go on vacation while they got some files checked out.
- 17:59That's the one thing.
- 18:00The other is you need permission to participate in a project.
- 18:05You have these gatekeepers and you need to sort of prove yourself to the gatekeepers.
- 18:09So if I wanted to commit, I wanted to work on Flask, if it was under Subversion, I have to go.
- 18:15Can I have permission to go read, get read-only access to Flask?
- 18:18If I want to make a change, I literally have to say I need permission to commit back to Flask.
- 18:22With the distributed ones, you clone it, you do your proof of work, your proposed idea.
- 18:28And if you want, you can contribute it back or you could just go in a different way, right?
- 18:33There's this very interesting separation of I can kind of work on it and then see if I want to contribute
- 18:39it back rather than the other way around.
- 18:41I have to get permission to contribute.
- 18:44And I think that's a super critical thing in the open source space where there's a very
- 18:47loose coupling of people and projects.
- 18:49Like if somebody comes to me and says, I want to work on, I suppose I'm working on Flask.
- 18:54They come to me, I'm in charge of Flask.
- 18:56They come to me and say, I want to work on Flask.
- 18:57Like, well, maybe.
- 18:59What else have you done?
- 19:01Show me.
- 19:01This is a huge project.
- 19:03We do not want you to mess up Flask.
- 19:06But.
- 19:07And we had a little bit of that with SourceForge.
- 19:10You know, you could clone the repository in Subversion and just work on it locally, but you
- 19:16weren't able to participate.
- 19:17The moment that you wanted to help, it was a really frictionful process where, you know,
- 19:22okay, so I have this diff.
- 19:24Now, I don't have write permissions.
- 19:26So am I going to, you know, bake this diff into an email and hope somebody reads it?
- 19:31Do I just use it locally?
- 19:33Do I fork the project and only have our corporate version of it?
- 19:37You know, it was very difficult to participate.
- 19:39And that's not a feature of Git per se, but rather the GitHub, the shared hosted mechanism
- 19:47around Git that has grown up as well.
- 19:49Yeah.
- 19:49I mean, with Git, you can clone a thing and then work on it as long as you have read access.
- 19:53But yeah, the additional mechanisms, the Git flow around it is certainly something created
- 19:58by GitHub with like PRs and forks and the emerging upstreams and all that origin upstream stuff.
- 20:06One thing I did want to ask you before we get to the details is why do you think Git won?
- 20:10You did talk about this Betamax, VHS sort of thing, and there are other options out there
- 20:15for distributed source control.
- 20:17I have a theory, but what are your thoughts?
- 20:19And I have a theory too.
- 20:20I don't have the answer and maybe our listeners will help us discover what the correct answer
- 20:26is, or maybe there isn't one.
- 20:27In my mind, a lot of the time we were looking at ways to compete with things.
- 20:33You know, we had things that would compete with CFS or subversion because, you know,
- 20:38we wanted a little bit more or we wanted to make money on the process of source control.
- 20:42And what's really interesting about Git is that it has become so pervasive.
- 20:48And so we're not building competitors to Git, we're building integrations into Git.
- 20:53All right.
- 20:53We're building on top of Git.
- 20:54Yeah.
- 20:55Now, arguably GitHub helped with that too.
- 20:57GitHub has a really, really powerful community mechanism for that.
- 21:02And GitHub really only did Git.
- 21:05But I would argue that Git is really cool because it's free and open source.
- 21:11And because it's free and open source and it has that community mechanism around it,
- 21:15we don't need to compete with it.
- 21:17We don't need to try to make money on this.
- 21:19Instead, we can build collaborations with it and mechanisms working with it and build up the
- 21:25community together.
- 21:26My thought as well was GitHub.
- 21:28Yeah.
- 21:28It's the thing that brought not just the server infrastructure to privately have code.
- 21:34It brought the community and it brought the flow that allowed people to collaborate in
- 21:40ways that could let them collaborate once they've proven they have something to collaborate.
- 21:45Right.
- 21:46Here's my PR where I've already shown you the thing that's amazing that I want to offer up
- 21:50to you.
- 21:50Well, that does look amazing.
- 21:52Thank you.
- 21:52Who are you?
- 21:53Let's talk about this.
- 21:54Right.
- 21:54It's a different conversation than I've never seen you.
- 21:57Why should I give you right access to Blask on SVN?
- 22:02And it's exactly that.
- 22:03GitHub has these magic levels to it where at the very first level, it is just an online
- 22:09source code repository system.
- 22:10And so how is that different from SourceForge or TFS before it?
- 22:16It isn't at this level.
- 22:18And so if that's what you're using GitHub for, then that's perfect.
- 22:22You know, back up your local projects up to GitHub, get your content off of your machine
- 22:27in case there's a disaster.
- 22:28That is definitely the first level.
- 22:30The next level starts to build workflows around it where we can say, I want to create issues.
- 22:35I want to create project management things.
- 22:38I want to create milestones.
- 22:39I want to create goals.
- 22:41And so that's kind of the next level.
- 22:42Leveling up again, we can start to create a social community around that where we can start
- 22:49to have conversations around the content where I can create a diff and we can all talk about
- 22:56it and we can collaborate on it.
- 22:58And once it's good enough, now we can pull it in.
- 23:01Add to that then the mechanism around pull requests and things like that.
- 23:06Git has a concept of push and pull.
- 23:09You know, publish and receive, I guess, might be the terminology that matches here.
- 23:15And what's interesting about a pull request, I don't have right access to your repository,
- 23:20but I want to contribute.
- 23:21So instead of pushing my content to you, I'm going to request that you pull it from me.
- 23:29And so no longer do I need to create this email and write out all the content and hope you read the email.
- 23:35I create this code up in my space and I request that you include it in your space.
- 23:43And that made collaborating with projects really, really easy.
- 23:49So with that comes the next level of GitHub where we have these communities that can socialize
- 23:54and develop and hang out in this coding space.
- 23:59And that's really what made GitHub so magical is that we have this community around coding.
- 24:05Where previously with SourceForge or other environments, yeah, we had that online source control system,
- 24:12but we didn't have those levels of interaction.
- 24:14So pull requests or merge requests or whatever you're going to call it,
- 24:18is that mechanism of being able to collaborate with low trust type of environments.
- 24:24I want to offer up my solution to the community and see if that's going to fit into this ecosystem.
- 24:30Yeah, I think that's why I get one as well.
- 24:32And Verda Rose out there says,
- 24:35open source is the best way to learn and improve technically and collaborate with people you don't know.
- 24:40Yeah, and I think it's that the people that you don't know,
- 24:43it makes it special because it allows you to create these connections with people all around the world
- 24:48who you would otherwise not meet.
- 24:51And you get a chance to work with them.
- 24:53Even if you live in rural Canada and you want to do software development,
- 24:58maybe no one around you is really good at whatever you're trying to do,
- 25:01but go to GitHub, find a project.
- 25:03You can collaborate with the best people in the world on that.
- 25:05We can create these communities around our passions for technology
- 25:09or the problems that we want to solve,
- 25:11not necessarily based on the geographic boundaries that we find ourselves in.
- 25:15Yeah, absolutely.
- 25:15All right.
- 25:16So that's the history of it a little bit.
- 25:19I talked a little bit on why distributed source control is really powerful.
- 25:23And I think it has really unlocked open source in a special way and on a much larger scale than it has.
- 25:30And it is interesting to note that Git and GitHub are different.
- 25:33GitHub uses Git under the covers to be able to build its social experiences.
- 25:38But Git is a thing that is separate and distinct.
- 25:42There is no pull request concept in Git, for example.
- 25:45And with Git on your local machine in a cave, you can version and create those save points.
- 25:53When you're ready to socialize, to publish your content, to communicate with your team,
- 25:57you can use Git together with lots of services, GitHub or Bitbucket or GitLab,
- 26:04or there's lots of private services as well that allow you to create that online community.
- 26:11You know, GitHub has published their magic sauce to the world and lots of us have cloned it.
- 26:16So GitHub is still the place where we code for the most part.
- 26:20But if you prefer coding in another community, then that's totally fine.
- 26:23You can still use Git and all of the tools to be able to create your save points and publish that content to others.
- 26:31You could just publish it to a different server as well.
- 26:33Git and GitHub are different.
- 26:35It's easy to see them as the same thing.
- 26:37But yeah, they're absolutely not.
- 26:39We've got all these different locations.
- 26:40I have mixed emotions, mixed feelings about if you have another project and you put it somewhere else,
- 26:46I'm not going to name any particular service, but let's just say somewhere that's not GitHub.
- 26:49That's totally good.
- 26:51But at the same time, so much of the open source flow is around GitHub and the stuff that's happening there.
- 26:57I don't know.
- 26:58It's just really interesting to think why you might be at one place and not the other place and so on.
- 27:03Yeah.
- 27:03And a lot of people were worried when GitHub was bought by Microsoft, is this going to be the end of the community collaboration?
- 27:10And I think Microsoft has been a really good steward of the GitHub community and really making sure that GitHub is still available to all of us and facilitating the success of that ecosystem.
- 27:23Yeah.
- 27:23There was a lot of hesitancy and concern within certain communities.
- 27:27And I feel like they've done a great job.
- 27:30Yeah.
- 27:31What I didn't realize was that GitHub really needed some help from somebody.
- 27:37financially, they were not doing as well.
- 27:40And I looked at them like, oh, this place must be incredibly successful.
- 27:43But what came out after some of the reports and stuff, it was kind of important that someone came along.
- 27:49And if that's the case, then I was head over heels that Microsoft bought them.
- 27:53Last thing I want to see is them go away.
- 27:55And I think they've done a good job of just letting them be.
- 27:57Don't go mess with them.
- 27:59It's working really well.
- 28:00So I think it's been a good deal that worked out there.
- 28:04See also Docker for an example of a community that is amazing and contributing, but doesn't have a financial business model to be able to survive.
- 28:12Yeah.
- 28:12Yeah.
- 28:13Hopefully things go well for Docker, but it's just tricky.
- 28:16They tried the enterprise thing and then they're switching to other things.
- 28:20Yeah.
- 28:21I love their pivot back to focusing on developers in the community, which is wonderful.
- 28:25But I still feel like they haven't found their spot that allows them to be business successful.
- 28:32And the hard part is you can only do that for so long and then you need to pivot to something that can start to facilitate the business.
- 28:41Yeah, absolutely.
- 28:41All right.
- 28:43Are you ready to go into the Git folder and find where the hidden magic lives?
- 28:47Yes.
- 28:48If you go into a project that you've Git cloned or you've Git inited and you create some files and you mess around there, you don't see anything different.
- 28:57It looks just like any other folder that might have a project in it.
- 29:01Right.
- 29:02But in there actually is contained the almost the entire backup, the entire contents of all the versions of those files.
- 29:11At least every branch that you've checked out hidden in the hidden .git file.
- 29:16So .git on.
- 29:19And it's not almost.
- 29:20It is.
- 29:20That is the entire history of the project.
- 29:24So the way to back up a Git database, misusing that term, is to grab that .git folder and copy it.
- 29:32Inside that .git folder is lots of files that describe the history of the project since its inception down to the current version.
- 29:41And so, you know, kind of the only way that you can break Git is to open up that .git folder and change stuff.
- 29:48By default, this folder is hidden on most systems.
- 29:52So you may have to show hidden files and folders to be able to see the .git folder.
- 29:56But it's there.
- 29:57And it's really powerful.
- 29:59Yeah.
- 29:59And so on Windows, you go to the Explorer, there's like one of those little ribbon things that drops down.
- 30:04It's a checkbox for show hidden folders and files.
- 30:06On macOS, I learned you can hit shift command dot and that will show hidden files.
- 30:12That I did not know.
- 30:13And I was very delighted when users told me about that.
- 30:17On Linux, I don't know.
- 30:19I mean, you can go and do an LL in there on the terminal.
- 30:21But there's probably some way to show it in the Explorer equivalent as well.
- 30:25You can navigate into it from your terminal or wherever.
- 30:28And once you're inside of it,
- 30:29Yeah.
- 30:30All of the files are right there.
- 30:31Yeah.
- 30:31So we go in here and we find things like head, config, description, hooks, index, info, logs, objects, hacked, refs, and refs.
- 30:40You want to maybe give us a rundown of what each one of these are?
- 30:44And then we can dive deeper with one of the tools that you built into maybe some of the things like refs and so on.
- 30:50But yeah, also maybe hooks.
- 30:52But yeah, wherever you want to start.
- 30:53What's cool in this database is it is the entire history of your project.
- 30:58And it's zlib compressed.
- 31:01So for example, the 20-year history of Perl, the .git folder is ever so slightly larger than the checkout folder.
- 31:12And that includes the entire history, including all of the changes and all of the authors and all of that is really nicely compressed into this folder.
- 31:21Wow.
- 31:21It breaks down into a couple of groups of things.
- 31:24We have the content.
- 31:26We have branches and tags, you know, references to the content.
- 31:32We have configuration details around this repository.
- 31:36We have index files.
- 31:38We have temp files.
- 31:40And then we have automation tools.
- 31:41And so these are kind of the groups of things that we'll find in this folder.
- 31:46A lot of them happen to be in their own folder, which is really nice.
- 31:50So for example, hooks is the place that you go for automation.
- 31:52Refs is the place where all of the content is.
- 31:55No, refs is the place for branches.
- 31:58Objects is the place for the content.
- 32:01And so a lot of the things that we'll see will have their own folder, but some of them spill out.
- 32:06Like configuration is in the config file, but there's also some stuff in the info folder for that.
- 32:12Indexes, we've got the index file right there on the root directory, but we also end up with index files inside of pack folders.
- 32:22And so, you know, it gets a little bit interesting.
- 32:25The first one to dive into is probably the objects folder, because this is the stash of all of the content in your repository.
- 32:33Now, as you commit something into Git, you'll first add it to the staging area, and then you'll commit it with a message.
- 32:41And as you do so, you'll end up with content inside the objects folder.
- 32:46Now, what's interesting to note here is if you look at a Git log, you'll see hexadecimal thing.
- 32:53You know, it might be seven characters, or it might be much longer than that.
- 32:57And as you do that log, you can take a look at that.
- 33:01Inside the objects folder are folders with two digits.
- 33:06Those are the first two digits of the commit number.
- 33:08Inside that folder is all of the commits that happen to start with that two-digit number or letter.
- 33:15So, you know, that means that not all of the files will be in one directory.
- 33:20They'll kind of be arranged a little bit.
- 33:22That gets around too many files in one directory.
- 33:25But it's that objects folder that then stores all of the content there.
- 33:31Now, what's interesting is I think of it, if I commit one, and that's where this talk was really cool.
- 33:37When I commit one thing and I go look in that objects folder, I will have three different files.
- 33:43Now, they are zlib compressed.
- 33:45Yeah, you can't just open them up and look at them, right?
- 33:48They're kind of scrambled up.
- 33:50But it's not magic.
- 33:51I built a tool that will unzlib compress one, which is pretty cool.
- 33:56But once we identify a thing that we want to do, we can also use git catfile.
- 34:02Git catfile allows us to look at both the type and the content in a particular node.
- 34:10This is a directional, acyclical graph nodes, DAG nodes, that specify relationships between these things.
- 34:19But what's cool is we...
- 34:21Here's a branch.
- 34:21Here's a file that's in that branch, something like that.
- 34:24They're not branches, but they are folders.
- 34:26Here's a file within a folder.
- 34:28Here's the content.
- 34:29So we have three different types of these nodes.
- 34:32One is a commit.
- 34:33And in the commit, we have the author's name and the date that it was committed, the message that we gave.
- 34:41And also in that commit is a reference to the tree nodes that are part of that commit.
- 34:48Now, each tree node can specify files or folders.
- 34:53So a tree node can reference another tree node.
- 34:55And inside the tree node, we have references to those files.
- 35:00So I might have a tree node that references file1.txt.
- 35:04The third type is a blob.
- 35:06And so as we look at blobs, then that's the actual content in the thing.
- 35:12So go back to the...
- 35:15Click on...
- 35:16Oh, I don't think I have a one to get back to the blob.
- 35:19But the cool part about this app, hit refresh, and you'll get to that big blob of stuff.
- 35:24Here's all of the commits in this repository.
- 35:28So we had something visually to look at here, and it's about to pull up its rendering.
- 35:31Yeah, it's not super performant.
- 35:33That's all right.
- 35:34You built this thing called Git-Explorer, which is a little web app that runs that you pointed at a Git repository.
- 35:41And it lets you look at these things that you're describing visually and then click around on them, right?
- 35:47Right.
- 35:47So click on Show Type, and we see the three different colors emerge.
- 35:51There are commits, trees, and blobs.
- 35:53And it's like, okay, I have a whole bunch of files in my objects folder, and I can click on each one, and I'll use that Git cat file thing to go figure out what it is.
- 36:03But it's like, you know, I really wish I had more stuff about it.
- 36:09So that's where I click alphabetical, and that will put them all in order.
- 36:14Click on Tags, and now you can see the name of that thing.
- 36:18And I'm only showing the first seven digits of the commit here.
- 36:22But now you can kind of get a sense for, here are all the objects, and click on each one and open it up.
- 36:27Right, and these names are what often go by shahs in Git parlance, which is just the type of hash, S-H-A, whatever it is.
- 36:37And I don't know how many people know this, but you can use sub pieces of the shah to refer to it in Git.
- 36:44So you don't have to say the full, I don't know, what is that, 32 characters or whatever to describe a name.
- 36:50As long as it's enough to be unique, it'll go, like, you can issue commands against these things in this abbreviated form, right?
- 36:56Right, exactly.
- 36:57So oftentimes, only two digits is necessary, sometimes three or four.
- 37:01And that's why often when you're looking at Git history, it'll only show you the first seven.
- 37:05Surely enough, yeah.
- 37:06Now what we start to do as we're clicking through this is we get a feel for all of these green nodes.
- 37:12That's the content in the files.
- 37:14The blue nodes are the tree nodes.
- 37:17And as I click on one of those blue tree nodes, then it references other files.
- 37:22I can see their shahs, their Git hashes there in that list.
- 37:27And then as I look at the red ones, the commits, that's my commit message.
- 37:30That includes the parent node that was the commit right before this.
- 37:35It also references the tree node that has the files for this.
- 37:39And so wouldn't it be nice if we could, I don't know, arrange them in a way?
- 37:43So let's, instead of going from alphabetical, let's click on parent-child and start to see the relationships.
- 37:50We'll need to turn on lines now, and we probably want to also turn on tags.
- 37:54And now we can take a look at those commits and see how each one references.
- 37:59Now, if you have a very large repository, then I haven't built scrolling yet.
- 38:05Sorry.
- 38:05But you can see that the red commit nodes all reference each other and reference the previous
- 38:13ones.
- 38:13And then they go into these tree nodes that may reference other tree nodes.
- 38:17And eventually those reference the file nodes.
- 38:19That's part of my demo highlight that if we create the same file content and commit it in
- 38:25two different directories, it's actually only one blob on disk.
- 38:30There's only one green blob node.
- 38:32But the cool part here is we were able to explore each of these objects in our repository and we
- 38:38get a feel for how they work.
- 38:39So if I change one line in a very big file, what gets committed?
- 38:44Well, the entire file.
- 38:46Yeah.
- 38:47And I'd suspect that's probably why large binary files are not ideal to be committed here, even
- 38:52though you technically can put them there.
- 38:54Right.
- 38:54So that's the first group of things is these objects.
- 38:57So that's the top level objects folder in the .git folder.
- 39:01Yeah.
- 39:01Yes, exactly.
- 39:02Now, there is a pack folder inside there.
- 39:05If you run various commands, then Git will say, well, do I have too many commits, too many
- 39:13of these objects that I need to pack together to make this repository smaller on disk?
- 39:20And if so, then it'll automatically do a GC, a garbage collect, where it starts to pack those
- 39:27into pack files.
- 39:28Now, it's kind of a Zlib compressed group of Zlib compressed files.
- 39:32So it gets very meta there.
- 39:34But that's what the pack folder is inside the objects folder.
- 39:37Yeah.
- 39:37Okay.
- 39:38So next up, let's talk about the refs folder.
- 39:40Now, when we look at refs, we look at branches and tags and remotes.
- 39:47These are files that reference commits.
- 39:51So one example is the head folder in the root of the .git directory.
- 39:56And inside that head folder, it will specify what head points to.
- 40:01So if you do a Git log and you see that head has an arrow pointing to, I don't know, main
- 40:06or trunk or develop or whatever, then if you open up that head file, you'll see the text
- 40:15in that file is that file.
- 40:17It's basically the SHA, right?
- 40:19Is that what it is?
- 40:19It is the SHA if your head is pointing at a SHA.
- 40:22But typically, your head won't be pointing at a SHA.
- 40:25It'll be pointing at a branch.
- 40:27Oh, yeah.
- 40:27Refs.
- 40:28Mine right now is refs slash heads slash main, which is the default branch for this project.
- 40:33So that's awesome.
- 40:34Main being the branch.
- 40:35Yeah.
- 40:36Head says it goes to refs, heads, main.
- 40:38So we can go into the refs folder.
- 40:40We can go into the heads folder.
- 40:42And we can open up main.
- 40:43And what's in main is the SHA of the commit that main points to.
- 40:49Okay.
- 40:49What's cool here is that each of these refs, both head and all of these branches, is just
- 40:56pointers to the commits in the objects folder.
- 41:00Yeah.
- 41:00So these are like the main file is just a text file that just literally has only the SHA that
- 41:06is where that branch currently is.
- 41:08Exactly.
- 41:09Okay.
- 41:09So technically, to create a branch, I just create a file that happens to be in refs, heads.
- 41:16I name it something and I give it a SHA.
- 41:18And now I have a branch that points at that thing.
- 41:22Branches in Git are not these durable, fragile things like in TFS or in Subversion.
- 41:28Branches in Git are just name tags.
- 41:31They're pointers.
- 41:32They're references to the commits in this tree of objects.
- 41:37So the cool thing is we can move them around.
- 41:39Right.
- 41:39They're basically a path of these named commits through the history of the overall history
- 41:44of it, right?
- 41:44Right.
- 41:45They're the labels that we give it so that we can understand it because communicating in
- 41:4932-digit SHAs is not as much fun.
- 41:52No, definitely not.
- 41:54Definitely not.
- 41:55One of the talks that I like to do is I do a Git log and I show that 32-digit hash and I
- 42:00read it out.
- 42:01And then I walk up to somebody in the audience and pretend they're the project manager.
- 42:05And I go, can I ship it?
- 42:07And they're like, yeah.
- 42:11Thus, we have these labels.
- 42:13Yeah, that's right.
- 42:14In the heads folder is all of the branches.
- 42:18In the tags folder is all of the tags.
- 42:23And there are also just files pointing at commits.
- 42:26Sorry, my repo is empty.
- 42:27I don't have any.
- 42:28But if you, you know, people might tag a release or a version or a beta version or something like
- 42:32that.
- 42:32So you can refer to it by name, by label instead of, you know, main with the SHA or
- 42:38something weird like that.
- 42:39Right.
- 42:39Right.
- 42:39And then we would have a remotes folder, which references where I last saw another copy of
- 42:48this Git repository's branches.
- 42:50Yep.
- 42:50So in this case, you have one that says refs, remotes, origin, main, and that's perfect.
- 42:55That's where I last saw this server, this server's main branch.
- 43:03Now, in this case, I chose to call my main, my remote server origin.
- 43:07Now, this could be a server that we've designated as the server.
- 43:12It could be one of my coworkers.
- 43:15It could be a network share.
- 43:17You know, Git isn't really opinionated about what constitutes a remote repository other than
- 43:23that it is in this one.
- 43:24Yeah.
- 43:24Okay.
- 43:25How does it know what origin is?
- 43:27As I create a remote, I'm going to name it.
- 43:30Okay.
- 43:30So as I clone, I'm going to say, Git clone this repository and it'll build one and it'll
- 43:36by default call it origin.
- 43:37But I could also say, Git remote add origin.
- 43:43I just gave it a name and then give it a URL.
- 43:45I could say, Git remote add upstream.
- 43:48I could say, Git remote add Michael.
- 43:51Now it's a reference from my repository to yours.
- 43:54And so it's just in this case, in the refs, remotes folder, it's just a folder
- 43:59referencing the branches that I saw on your machine.
- 44:02Nice.
- 44:02Is there somewhere where it stores like the URL?
- 44:04It does.
- 44:05And that is the next section that we may want to look at, which is configuration.
- 44:09Let's open up the config file in the root of the .git folder.
- 44:14All right.
- 44:15Now this configuration file is really cool.
- 44:17It includes all kinds of configuration details associated with our repository.
- 44:22Now in this case, we have remote origin where we've named this one and here's the URLs that
- 44:28we go to there.
- 44:28In this case, it's github.com/talk Python.
- 44:31We have other configuration details associated with this repository.
- 44:37This .git config file is actually one of three on my machine.
- 44:44And we'll start out with our config file that's installed when we install Git.
- 44:51So it's probably in program files or it's in user local bin or somewhere off in the ether
- 44:59of how we install it.
- 45:00We probably don't want to touch that one.
- 45:02But that's the base configuration of all the options that we chose when we installed Git.
- 45:07So if I run a command, if I were to say something like git email global, something like that,
- 45:14you know, the .g command, maybe it's modifying that one.
- 45:16Well, the one that we just talked about was the system one.
- 45:19The second one is the global one, which is user specific.
- 45:22I find that name a little confusing.
- 45:24But my user specific, the .git config in my user home directory.
- 45:30So, you know, see users rob or user or the tilde slash directory Mac and Linux.
- 45:38That .git config overrides any settings in my system configuration.
- 45:44And so oftentimes when you first install Git, you'll say git config dash global user.email user.name.
- 45:52And so if you open up that .git config in your user home directory, you'll see those settings.
- 45:58You'll see your username, your name, your email, and all of the details that you've configured there.
- 46:06And then the third one is the config file here in your repository that will override any of those settings.
- 46:13So it doesn't make sense for us to have origin in our system, in our user specific configuration file,
- 46:21because, well, each repository will have a different origin.
- 46:25But it probably does make sense to put our name and email in our system, in our user specific directory,
- 46:31because that would apply to all the repositories on our machine.
- 46:35Yeah, absolutely.
- 46:36Almost all of them.
- 46:37You might be doing home-based open source work, and you might be doing corporate button-up work,
- 46:43and your formal corporate place might not love your corporate email on the open source project.
- 46:49Exactly.
- 46:50Or maybe you don't have it.
- 46:51Exactly.
- 46:51Yeah.
- 46:51So when I have that scenario where I need to set my email address,
- 46:56maybe my name differently in different repositories,
- 46:59I can set it in my .git config in my user home directory,
- 47:04and then I can override it in each repository.
- 47:07Just copy those couple of lines, set them in your config file here,
- 47:11and now you've set this repository to track your email differently.
- 47:16Is there a git command to change it so I don't actually go into the .git folder,
- 47:21and I say, like, git email but not global, or git config email?
- 47:24Yeah.
- 47:25Leave off the --global.
- 47:26Yeah.
- 47:26Okay.
- 47:27Perfect.
- 47:27Then you don't even have to know how.
- 47:30You just know I do git email and what my email is.
- 47:32Right.
- 47:33Now, there are other configuration files here in the .git folder,
- 47:38but the config file is really the big one that we like to talk about.
- 47:41Yeah.
- 47:41Okay.
- 47:42But you'll see a description file here.
- 47:44That's a configuration file.
- 47:46Git InstaWeb is a web server baked into Git
- 47:51that allows you to kind of browse through your repository.
- 47:55Now, Git InstaWeb works pretty well on Linux and not so great on Windows.
- 48:00I bet you've never used InstaWeb in most scenarios.
- 48:04I'd never heard of it until you brought it up the other day.
- 48:07Yeah, but this configuration file is the name of the website
- 48:11when you launch Git InstaWeb.
- 48:13Yeah, so Git ships with a web server that can be the host of that Git repository.
- 48:17Yeah.
- 48:17Now, why would I ever do that?
- 48:19Why wouldn't I just use GitHub?
- 48:20Exactly, which is why you've never heard of Git InstaWeb.
- 48:23Yeah.
- 48:24I mean, you might say we want a private Git server or a public Git server
- 48:28or something like that.
- 48:29That might be.
- 48:30But yeah, usually, yeah, I've never heard of it.
- 48:32So very interesting.
- 48:33All right.
- 48:34What else is in this list here?
- 48:36Yeah.
- 48:36Yeah.
- 48:37So we've talked about the content in the objects folder.
- 48:40We've talked about the branches and tags in the rest folder.
- 48:43We've talked about configuration.
- 48:45Let's go poke in the hooks folder.
- 48:47Yeah.
- 48:47Hooks is interesting.
- 48:48Yeah.
- 48:49It is really cool.
- 48:50The hooks folder is where we do automation.
- 48:53Yeah.
- 48:53So people probably heard of pre-commit hooks, right?
- 48:57Like probably the most popular example in the Python space is to run the black formatter.
- 49:02So it automatically formats your code before it checks it in.
- 49:05So indentation, white space, like between a comma and an argument or something.
- 49:11It's always consistent.
- 49:13So you don't get these like back and forth editor driven, you know, merge issues.
- 49:17There's no real change.
- 49:18But I format it in my editor.
- 49:20You format it in yours.
- 49:22And back and forth, it goes between spaces with a comma and no spaces with a comma,
- 49:25spaces with a comma.
- 49:26And so you could set up a pre-commit hook to canonicalize it before it goes in.
- 49:32But there's more than pre-commit, right?
- 49:33Yeah.
- 49:33I could set up a pre-commit hook to make sure all my unit tests pass before I commit.
- 49:38I could set up.
- 49:40And so what we see here in this hooks directory is all different kinds of automation things.
- 49:47So a pre-commit hook, a pre-merge hook, a pre-push hook, a pre-rebase hook.
- 49:53And each of these are shell scripts.
- 49:56Well, with one exception, it's a Perl script.
- 49:58But you see at the very top, it says slash bin slash sh.
- 50:02Well, I'm on a Windows box.
- 50:04Is this shell script still going to work?
- 50:06Well, yeah.
- 50:07Get ships with enough Linux-y, Unix-y, Bash-like stuff to be able to kick off these shell scripts
- 50:14and run them as it would on any Linux system.
- 50:17Okay.
- 50:17Interesting.
- 50:17So there's basically like a little mini Bash that comes with it.
- 50:21I remember people using that Bash shell from Git.
- 50:23It'd be more Unix-like on Windows.
- 50:25Exactly.
- 50:26So here in this shell script, I could do all kinds of things.
- 50:29Maybe I'm calling a PowerShell script.
- 50:31Maybe I'm calling a Python script.
- 50:33Maybe I'm calling a Node formatter.
- 50:35I can just call into whatever tasks I want to accomplish.
- 50:38And that will then accomplish that task whenever this event happens.
- 50:44So what I love to do in my demo is remove all the dot sample pieces so that they're actual scripts.
- 50:50And then just merely the presence of that file will be able to kick off that automation.
- 50:55All right.
- 50:56So there's a bunch of files that are sample shell scripts named things like pre-commit.sample or pre-merge commit sample.
- 51:03If I just called it pre-commit but not the dot sample, now it's going to be active?
- 51:08Exactly.
- 51:08Okay.
- 51:09Nice.
- 51:10Now the cool part about these is that I have all my automation set up.
- 51:13I'm running the formatters.
- 51:15I've got my unit test passing and it's great.
- 51:18But this file is inside my dot git folder.
- 51:21So I can't commit these.
- 51:23It's not one of the files that is available for me to add to the staging area.
- 51:27Right.
- 51:27It would be Inception if you tried to commit stuff in the dot git folder.
- 51:32Right.
- 51:33So often we'll create shell scripts outside the dot git folder and commit them and then have something here inside the dot git folder that calls into that other shell script.
- 51:44Yeah.
- 51:45And you mentioned some kind of node-based tool that you can use, right, that will manage that stuff, right?
- 51:50Right.
- 51:50There's lots of packages.
- 51:51The one that I show is git hooks that is an npm package.
- 51:56And once you install git hooks, it will actually create all those aliases from the folder where you actually build the scripts that you can commit into this hooks directory so that then they'll run.
- 52:08Just installing this package installs those hooks into place.
- 52:11I see.
- 52:11So basically, if you just install the package once, it will find those other external scripts and make those be the ones that git sees with the advantage that you can commit them into GitHub.
- 52:24And if somebody makes a change, that change will propagate to everyone else.
- 52:26Yes.
- 52:27You can commit them into git, push them up to GitHub, and they will run.
- 52:31Okay.
- 52:31Yeah.
- 52:32Fantastic.
- 52:32Yeah.
- 52:32Yeah.
- 52:33Very neat.
- 52:33Very neat.
- 52:33Okay.
- 52:34What else have we got here?
- 52:35What else have we got?
- 52:36I think maybe index, maybe?
- 52:38That's an interesting one.
- 52:39Yeah.
- 52:39Index is really interesting.
- 52:41As we look through index, if we just pop it open in an editor, it's just a bunch of gobbledygook.
- 52:48And we're like, what is this?
- 52:49It's a file, right?
- 52:50Yeah.
- 52:50Yeah.
- 52:51This isn't the only index, but this is one of the really cool indexes where git keeps track of interesting stuff.
- 52:58That's nice.
- 52:59Yeah.
- 52:59Check out this blown up.
- 53:00If I try to look at it, it's like a binary blob exploded and died on my terminal.
- 53:06But there are file names in there somewhere, so it must be something to do with that.
- 53:09Yeah.
- 53:09I think it's git ls-files, where you can go look through this index.
- 53:14And if we pass in flags to that, then it'll be able to show the status of those files.
- 53:19But this is looking through that index.
- 53:22And the cool part about looking through that index is that git, if it wants to do a quick thing,
- 53:29like which files have changed, needs to know the blob that is checked out in my working directory.
- 53:36You know, which blob did I start with?
- 53:39Right.
- 53:39As we look through those objects, we saw a big tree of things.
- 53:43And so opening up each commit node, finding all the tree nodes, opening up each tree node,
- 53:48finding all the blob nodes, that takes a while.
- 53:51And so this is a cache, an index, of all the files that I checked out in my working directory.
- 53:58This allows git to move really fast as it looks through my folder and identifies any files that have changed or new files or things like that.
- 54:08So that's what this index file is for.
- 54:10Yeah.
- 54:11And my git incantations are not pulling it up here, but I think you can get it to show the shah of each file as well, right?
- 54:17Right.
- 54:17In which case, then instead of traversing the whole history and actually looking at the file on the hard drive and saying,
- 54:24well, what is its hash?
- 54:26Do I have an update for this file?
- 54:28I could just look in this binary file and get that answer, right?
- 54:30Exactly.
- 54:31Nice.
- 54:32Yeah.
- 54:32The next section of files that we want to look at are logs.
- 54:36And the cool thing about git's logs is they keep track of where all of our branches have been.
- 54:45So if we cat.git slash logs slash head, then we get a thing that kind of looks really weird.
- 54:52We've got really long lines in this.
- 54:54And in our first line, it says a whole bunch of zeros.
- 54:58And then we've got the git shah of the commit that it went to and a little bit about that commit.
- 55:04This is a log of where our branches have been.
- 55:10And so we'll have a file for each of our branches.
- 55:13In this case, we're looking at the head file.
- 55:16So we see that head started out nowhere and ended up at ed13fc.
- 55:20And then it has my username, my email, and then some other stuff.
- 55:24Yeah.
- 55:24The really interesting thing is this log can be really useful if, for example, I switch branches
- 55:32and forgot where I was.
- 55:33Or I commit something and then I uncommit it.
- 55:37That's a thing.
- 55:38And I want to get back to it.
- 55:39Or I delete a branch before I merged it in.
- 55:42Or, you know, those types of things.
- 55:44If I do that quickly enough, you know, remember git's going to do that garbage collect and go prune nodes that aren't used anymore.
- 55:51If I get there quickly enough, I can use this log to go back through my refs and go find that commit.
- 56:00The objects are still there.
- 56:02I just don't have any refs pointing to them anymore.
- 56:04And so the command that we can use on the command line is called git ref log.
- 56:08And we can pass git ref log a particular branch we want to look at.
- 56:12But by default, if we just say git ref log, all one word, then it will show the history of head.
- 56:19Now, in this case, we didn't move it very far.
- 56:22But we can see there, oh, and here's the branch that I just deleted.
- 56:26And here's the SHA for this one.
- 56:29And so at that point, then we can git checkout that commit and get back to the content that we had created and then lost the reference to.
- 56:38Right. Okay. Nice.
- 56:39There's a little bit of recovery, kind of an undelete if you had to in there.
- 56:43Yeah.
- 56:44Nice.
- 56:44The funny thing about this, the command is git ref log.
- 56:47But I've also heard it pronounced git ref log.
- 56:50And I'm like, so I've got this cat of nine tails.
- 56:53And I'm like, no, you can't.
- 56:54Git ref log.
- 56:56Exactly.
- 56:56Do it again.
- 56:57But once you understand how the refs folder works, then git ref log makes a whole lot of sense.
- 57:03We're looking at what those ref files have said in the past.
- 57:08Here's what it was before we changed it.
- 57:10Here's what it became after we changed it.
- 57:12And a little bit more context around it.
- 57:14Where you're currently working is where the head is pointing.
- 57:17Often that's some point in a branch.
- 57:18And this is like, where's the history of that bin throughout the branch that it's on?
- 57:24Yes.
- 57:24Yeah.
- 57:25Very cool.
- 57:25Very cool.
- 57:26So we're getting sort of short on time here.
- 57:28What else should we be talking about?
- 57:31What else should we close this out with in terms of content of our .git file?
- 57:37The only other section in here is temp files.
- 57:41So if we've committed stuff, we might see a commit underscore MSG file.
- 57:47Or maybe it's called commit underscore message.
- 57:50We might see other temp files.
- 57:52We have a temp folder sometimes baked into things.
- 57:56And so that's the last group of files here in the .git folder is temp files.
- 58:01Temp files, configuration, objects, refs, hooks.
- 58:06These are all the pieces that come together to make this git database.
- 58:10And once again, you really can't break git.
- 58:13You know, it's like, well, I did this incantation and it's broken.
- 58:16Well, no.
- 58:17You can use ref log to get back to a particular commit.
- 58:20Or you can use various commands, checkout to get back to where you need to.
- 58:25Maybe you'll use reset to, you know, kind of get your working directory back in shape.
- 58:30But that structure of git, the double entry bookkeeping inside this repository, is really
- 58:37good at keeping track of the things.
- 58:39And so you really can't break git.
- 58:42Yeah.
- 58:42And back this up.
- 58:44You back it up, right?
- 58:45You back up this folder.
- 58:46You back up basically everything, right?
- 58:48All right.
- 58:49Now, it might be easier to back it up, not by just backing up this folder, but by publishing
- 58:53your changes to another repository.
- 58:55And that's where we have great workflows.
- 58:57Like, I will push all of these changes to another server.
- 59:01Maybe I'll call that server origin.
- 59:03Yeah, absolutely.
- 59:03And that is automatic if you check out from somewhere like, clone it from somewhere like
- 59:07GitHub.
- 59:07Right.
- 59:08GitHub.
- 59:08So there's just a couple other things maybe I want to touch on really quickly while we
- 59:12have a moment.
- 59:13When you talked about breaking git, there's an interesting little design thing called dangit,
- 59:19git, or even better.
- 59:20Maybe I'll link to the better version, the not safe for work version where you're frustrated
- 59:24and it's like, oh no, I just did something terribly wrong.
- 59:27Please tell me how to do it.
- 59:28And reflog is right at the top of these things.
- 59:31I committed and immediately realized I need to make a change or I need to change my commit
- 59:36message.
- 59:37And yeah, anyway, that's a pretty interesting one.
- 59:39Another thing we've talked a lot about GitHub.
- 59:41And what we haven't really talked about is gitignore, right?
- 59:46As much as you want to track stuff, you don't want to automatically track a bunch of things
- 59:49that are working files, you know, build stuff from C++ or maybe node underscore modules
- 59:56or PyCharm working files or all sorts of things should not go into your project, right?
- 1:00:03Your vn directory.
- 1:00:04Yeah.
- 1:00:05Yes, exactly.
- 1:00:06Your vn directory.
- 1:00:07Absolutely.
- 1:00:07So there's gitignores.
- 1:00:10Any content that you download, any content that you compile, any of that content shouldn't
- 1:00:16be in your repository because it changes too infrequently and it's usually easier to either
- 1:00:21rebuild it or redownload it.
- 1:00:23All those things should be ignored.
- 1:00:25Yeah.
- 1:00:25It's a huge merge nightmare as well.
- 1:00:28Even if you could keep it, right?
- 1:00:30Suppose I check in my vn directory and you go on Windows.
- 1:00:34Well, you can't have the same contents as mine because mine is the macOS version.
- 1:00:38So you change it, put your Windows version in there and I get it back out and it breaks
- 1:00:42my Mac versions.
- 1:00:43I got right.
- 1:00:43So there's stuff you should ignore.
- 1:00:44Absolutely.
- 1:00:45And when you create a new project on GitHub, it very handily says, hey, what kind of project
- 1:00:52is this?
- 1:00:52We can get you far down the road with your gitignore.
- 1:00:55Is this a Python project?
- 1:00:56Is it a node project or whatever, right?
- 1:00:58What I wanted to point out is that dropdown list.
- 1:01:02There's actually a GitHub project called gitignore that has the ignore for all of these different
- 1:01:09languages.
- 1:01:09So if you want to make a change to say Python's gitignore, you can go there and pull it up
- 1:01:15and see it.
- 1:01:16And you could technically do a PR against it to say there's this new thing that's common
- 1:01:20in the community now.
- 1:01:21Please fix it.
- 1:01:22That's pretty cool.
- 1:01:23And these things aren't perfect.
- 1:01:25You know, most of them will exclude everything that starts with or ends with or contains
- 1:01:30log.
- 1:01:30But your iLogger or your log handler might get excluded by that as well.
- 1:01:37So you may need to adjust this to get it the way you want.
- 1:01:41Yeah.
- 1:01:41But it is nice to know that at least it'll give you a bit of a start and that it's a thing
- 1:01:46that you can contribute back to.
- 1:01:47It's not just magic inside of GitHub, but it's its own GitHub open source repository.
- 1:01:52Right.
- 1:01:52Yeah.
- 1:01:52Quite neat.
- 1:01:53Quite neat.
- 1:01:54Let's see.
- 1:01:55What else should we cover really quick?
- 1:01:57I think maybe just one other thing I think that's maybe worth throwing out there that was
- 1:02:01interesting, but it's pretty specific.
- 1:02:03But you've mentioned Windows a couple of times.
- 1:02:05Maybe two things, actually.
- 1:02:07One is on the shell that you saw on my screen just a minute ago, when I was inside of a git
- 1:02:12repository, it would actually put what branch it was on and the git state and so on.
- 1:02:18And I have that because I have OhMyZShell installed.
- 1:02:22Which is a really nice shell for Mac and Linux that gives you things like branch awareness
- 1:02:28and number of changes and so on.
- 1:02:30I saw your talk.
- 1:02:31You had something like that for PowerShell, the new Microsoft terminal.
- 1:02:36What were you using for that one?
- 1:02:36It's called OhMyPosh.
- 1:02:38And Scott Hanselman has a really cool video about OhMyPosh where he walks us through how
- 1:02:44to get it installed.
- 1:02:45There are various themes into OhMyPosh, but the theme that I really enjoy actually puts the
- 1:02:50cursor on the next line.
- 1:02:52One of the things that I frequently do in command prompt is I have all of the path to get to
- 1:02:57this folder.
- 1:02:57And so the command that I'm trying to teach ends up getting wrapped to the next line.
- 1:03:01And so OhMyPosh or OhMyZSH gives you that additional context of how's your git repository
- 1:03:09doing?
- 1:03:09You could also show your remote.
- 1:03:11It's basically just running a shell script behind the scenes.
- 1:03:15And so you can modify that shell script.
- 1:03:17Scott Hanselman is diabetic and so needs to check his blood sugar a lot.
- 1:03:21And so he actually has built into his OhMyPosh script, his blood sugar number, because it's
- 1:03:28really easy to miss.
- 1:03:28And it's one of those things that's really important not to miss.
- 1:03:31So it's in his terminal all the time.
- 1:03:33Probably even color code it, right?
- 1:03:35If it's out of range, make it red.
- 1:03:37If it's not out of range, you make it green, something like that.
- 1:03:39Yes.
- 1:03:40Wow.
- 1:03:41How interesting.
- 1:03:42Yeah, this looks fantastic.
- 1:03:43I've never played with this before, but yeah, it looks really nice.
- 1:03:47You recommend it?
- 1:03:48Yeah, I do.
- 1:03:49Cool, cool.
- 1:03:49All right.
- 1:03:51Well, I guess the one other thing that I was going to throw out there is I heard of this
- 1:03:55thing called VSF for Git.
- 1:03:57We talked about large files and this sounds like it's very much a Windows only thing, but
- 1:04:04it's a neat idea.
- 1:04:05This virtual file system for Git that if you have a really large repository, it's kind of
- 1:04:10like the smart sync for Dropbox or something.
- 1:04:13It only pulls the files and interacts with the files that you actually touch, but it does
- 1:04:18that behind the scenes without you knowing it.
- 1:04:20Have you seen this?
- 1:04:21Yeah.
- 1:04:21And we actually said VSF for Git, but it's actually VFS for Git, virtual file system.
- 1:04:28It's great when your repository is just massively huge.
- 1:04:32And 98% of our repositories are not.
- 1:04:35But when you have the code base of, I don't know, Windows, then you need something like
- 1:04:41this because you can't Git clone the entire thing.
- 1:04:43GitHub, not GitHub.
- 1:04:45Google is famous for having their corporate monorepo.
- 1:04:49And I suspect that's bigger than you could Git clone onto each machine as well.
- 1:04:54And so the cool part is one of the benefits of subversion that we lost as we moved to Git
- 1:04:59was I could clone only part of a repository.
- 1:05:03And VFS kind of gives us that ability back.
- 1:05:07Most of the time we don't need it.
- 1:05:09But if you've been really bad and you've committed a whole bunch of binary files to your repository,
- 1:05:14it's interesting.
- 1:05:16It might be worth kicking the tires.
- 1:05:17It isn't necessarily Windows only.
- 1:05:19It is plug-in to Git itself.
- 1:05:21But it allows you to put that checkout directory somewhere else.
- 1:05:26So, for example, on a shared network drive.
- 1:05:30Now I have all of those objects, all of those blobs in one place,
- 1:05:35and I don't need to copy each of those to my machine.
- 1:05:38Yeah.
- 1:05:38Interesting.
- 1:05:39The Windows people that were switching to Git said it was really a nightmare.
- 1:05:44So, for example, the source code for Linux repo is something like 600 megs or 0.6 gigs.
- 1:05:50Windows is like 270 gigs.
- 1:05:52So it's really ginormous.
- 1:05:54And they said to do a clone took 12 hours.
- 1:05:57To do a checkout took three hours.
- 1:05:59To do a Git status took eight minutes.
- 1:06:01And to do an add and commit took 30 minutes before they made this change.
- 1:06:05So they were suffering some hard pains to go down this path for sure.
- 1:06:10I guess it probably is worth it for them.
- 1:06:12Right.
- 1:06:12All right.
- 1:06:13Well, I guess we probably should put a bow on it.
- 1:06:15We're more or less out of time there, Rob.
- 1:06:17But I'll ask you the two questions I always ask at the end of the show.
- 1:06:20If you're going to write some code, what editor do you use?
- 1:06:23It depends on the code that I'm trying to write.
- 1:06:26In most cases, I'll reach for VS Code.
- 1:06:28But I'll also reach for Visual Studio.
- 1:06:31Right.
- 1:06:31If you're going to be doing ASP.NET stuff, like you said.
- 1:06:33Sometimes I'm also known to reach for...
- 1:06:36If you're doing like ASP.NET or something you were talking about like that or something you could...
- 1:06:40Maybe something like WPF where the tools are built in.
- 1:06:43You have to basically...
- 1:06:44Not have to.
- 1:06:44Almost have to use them.
- 1:06:45But sometimes I also reach for Sublime Text or TextEdit.
- 1:06:48Cool.
- 1:06:49Cool.
- 1:06:49And then often ask for a Python package library recommendation.
- 1:06:53Maybe we could make it your Git script.
- 1:06:57The one that runs the pre-commit stuff.
- 1:06:59The one that moves that outside the Git file.
- 1:07:01What was that called again?
- 1:07:02It's called Git Hooks.
- 1:07:03Git Hooks.
- 1:07:04And let me grab a link to it.
- 1:07:06It's actually a Node package, but exactly.
- 1:07:08Yeah.
- 1:07:08You just install it wherever.
- 1:07:09And it's good to go, right?
- 1:07:11Yes.
- 1:07:11And so if you have maybe a Flask server and you want to...
- 1:07:16As part of your Flask server, maybe you have a React or a Vue app or you need to pull down
- 1:07:21jQuery as part of your client-side dependencies, then you may have enough Node stuff to be able
- 1:07:27to leverage this as well.
- 1:07:29Yeah.
- 1:07:29Yeah.
- 1:07:29That makes a lot of sense.
- 1:07:30If you're already using npm because you're doing front-end stuff, then you might as well,
- 1:07:35right?
- 1:07:35Yes.
- 1:07:35Yeah.
- 1:07:36Very cool.
- 1:07:36One of the things that we didn't talk about, and it's really cool how this happened,
- 1:07:39Git workflows.
- 1:07:40What's beautiful about Git is it's really unopinionated about how you do your workflow.
- 1:07:46Are you going to do GitFlow?
- 1:07:47Are you going to do GitHub Flow?
- 1:07:49Are you going to do something else?
- 1:07:51Git can work for all of those scenarios because it is just a mechanism of committing and sharing
- 1:07:56files.
- 1:07:57It doesn't impose a specific branching or naming convention.
- 1:08:02You can choose to put those on top, but Git's workflow is really open to whatever you need
- 1:08:09it to do.
- 1:08:09Yeah.
- 1:08:09Well, when I was first getting familiar with this whole PRs and merging and those kinds
- 1:08:15of things, I felt like, oh, that's a Git thing.
- 1:08:17That's a GitHub thing.
- 1:08:18It has nothing to do with Git, right?
- 1:08:20It just Git facilitates that on top of it.
- 1:08:22So you can choose however you want to work, right?
- 1:08:24Right.
- 1:08:24Quite cool.
- 1:08:25All right.
- 1:08:25Well, I don't normally close out this show with a joke, but Robynson had a good one here
- 1:08:31in the live stream.
- 1:08:31So I'm going to put this up here for us as our parting thought.
- 1:08:34And then I'll ask you for one more as well, maybe.
- 1:08:36Yeah.
- 1:08:36So he said, there's a programmer who once told him, couldn't use Git.
- 1:08:41He was afraid to commit.
- 1:08:43He was afraid of the Git commitment.
- 1:08:47Oh, that's awesome.
- 1:08:49Yeah.
- 1:08:49Yeah.
- 1:08:50Yeah.
- 1:08:50Thank you for that.
- 1:08:50Thanks for making us laugh.
- 1:08:51All right.
- 1:08:52Find a call to action.
- 1:08:52People want to go a little bit deeper than Git.
- 1:08:54Maybe they just do the three commands, Git clone, I don't know, Git add, Git commit,
- 1:08:59Git push.
- 1:09:00Like that's four commands.
- 1:09:01Like beyond that, like how do you get more into this world?
- 1:09:04What's really interesting is as we're coming off of those other systems, we want to kind
- 1:09:09of build up that tribal knowledge that we had.
- 1:09:12And so we're going to go grab those three or five commands and we're going to stick them
- 1:09:15to the post-it under our keyboard.
- 1:09:17Take the next step to go figure out, you know, what is the next command that I want to do?
- 1:09:23Or how does this command work?
- 1:09:25What we did today was we explored through that .git folder so that we could take that next level
- 1:09:31to see how it works.
- 1:09:32Git isn't a black box.
- 1:09:34It's not magic.
- 1:09:35It just works a little bit differently than the source control system you might have been
- 1:09:39familiar with.
- 1:09:40So definitely get familiar with it.
- 1:09:42Google the terms that you're looking for and really start to embrace that mechanism and
- 1:09:48get really powerful with Git.
- 1:09:49I'm confident that you can get past just those few commands and you can make it just an inherent
- 1:09:55process in your workflow and use it to be really, really powerful.
- 1:09:59Specifically, separating the save points from the publish points.
- 1:10:03That's the thing you couldn't do before that you can now do with Git.
- 1:10:06Yeah, well said.
- 1:10:07Definitely agree with all of that.
- 1:10:09I think getting really good with source control and source control these days really means Git
- 1:10:14almost.
- 1:10:14It allows you to be fearless with your code, right?
- 1:10:18So often people are like, oh, I would like to try this, but what if I break it?
- 1:10:21What if it doesn't go right?
- 1:10:22Well, if you know how to create your branches, work locally, do all sorts of stuff, roll back,
- 1:10:28you can just go crazy and just explore things.
- 1:10:31And if it doesn't work, throw it away.
- 1:10:32No harm, no foul.
- 1:10:33It's lovely.
- 1:10:34And if you get really stuck, hit me up on Twitter at Rob underscore Rich and show me the code where
- 1:10:40you got stuck and let's get you unstuck because I would love to continue this conversation and
- 1:10:45really help you be successful.
- 1:10:46All right.
- 1:10:47Well, thank you for taking the time and being here.
- 1:10:49It's been great to chat, Git with you.
- 1:10:51Most definitely.
- 1:10:52Thanks for having me on.
- 1:10:53Yeah.
- 1:10:53See you later.
- 1:10:54This has been another episode of Talk Python To Me.
- 1:10:58Our guest on this episode was Rob Richardson.
- 1:11:00It's been brought to you by our courses over at Talk Python Training.
- 1:11:04Want to level up your Python?
- 1:11:06We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:11:10Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:11:15And best of all, there's not a subscription in sight.
- 1:11:18Check it out for yourself at training.talkpython.fm.
- 1:11:21Be sure to subscribe to the show.
- 1:11:22Open your favorite podcast app and search for Python.
- 1:11:25We should be right at the top.
- 1:11:27You can also find the iTunes feed at /itunes, the Google Play feed at /play and the direct
- 1:11:33RSS feed at /rss on talkpython.fm.
- 1:11:37We're live streaming most of our recordings these days.
- 1:11:39If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:11:47This is your host, Michael Kennedy.
- 1:11:49Thanks so much for listening.
- 1:11:50I really appreciate it.
- 1:11:52Now get out there and write some Python code.
- 1:11:53I'll see you next time.
- 1:12:14Bye.
- 1:12:14Bye.
- 1:12:14Bye.
- 1:12:14Bye.
- 1:12:14Bye.
- 1:12:14Thank you.