Check out a free preview of the full Everything You'll Need to Know About Git course

The "git config" Lesson is part of the full, Everything You'll Need to Know About Git course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen discusses the importance of configuring Git and explains how Git's config works. He explains that Git config is similar to JavaScript's object design, with global and local settings. Setting the user.name and user.email in the Git config for creating commits is also demonstrated in this lesson.

Preview
Close

Transcript from the "git config" Lesson

[00:00:00]
>> By the way, everybody, if you're following along, you really do want to kind of make sure you have the same experience I'm gonna have. And so I want you to try to make a get into its default kinda setting. So if you've set an initial branch, you may want to turn that off for now.

[00:00:16]
You can tell by just taking this command, copying and going to the command line and putting it in. I have one right there, so I'm gonna do the same thing, and I'm just gonna go like this, unset. And so now, there's nothing there. And so I have the commands right here on the screen, please unset any init.defaultBranch.

[00:00:34]
You don't have to, but we're gonna be setting it along the way. Also, if you have rerere.enabled, it'd be good if you don't have rerere.enabled for this. Because if you do, you'll kind of miss out on some of the reasons why git is kinda fantastic. So awesome, now that we have this, we can keep on going.

[00:00:51]
So everybody, hopefully, you have all of your default settings properly set up, well, it's time to get good, okay? I'm ready to get good, hopefully you are. So how things will be structured? Every section's gonna come with some kinda question and answer part, where I'll say, hey, here's a thing.

[00:01:08]
And then you're gonna look at the thing, and hopefully, you'll internalize it. Then I'll ask you a question like, all right, let's stage the files. And if I use these terms, hopefully you remember what they all mean, and then you're gonna be able to do it fantastically. You guys will all be awesome, and everyone will get a promotion when they're done here.

[00:01:22]
Before we begin, you want to configure your git experience. This is that one thing you do when you first set up your computer, and that you've completely forgotten how it works. You just know you did it at some point in your lifetime, and now we're gonna do it again.

[00:01:35]
git config is a lot like JavaScript's Object.assign, you have your globalConfig, which should be for every single project. And then you can have your specific project level config. So maybe in one project, I only wanna use rebase, and another project, I don't want to use it. Maybe in one project, I wanna have it under my personal name, whereas I want all my projects to be under, say, my work email.

[00:01:56]
And so you can kind of set them up individually so you don't goof it up. It's very, very nice. So some key facts, all git keys are in the shape of <section>.<key>, is really important to remember. Cuz if you don't remember that, you'll get these weird errors, and they'll feel kind of arcane.

[00:02:14]
Remember, <section>.<key> is the key to any git config. global means it's for all projects, user.name and user.email are the keys used in helping create a commit. So when future you looks in the past and tries to do a git blame, who do they see other than yourself? Well, it's driven by these two things right here, user.name and user.email.

[00:02:38]
So to add something to your config, you do git config add, then you can do global and the key and a value. So just like you just think of it like a hash map, right, it's pretty straightforward. You can view anything with git config -get and then the key name.

[00:02:54]
All right, so pretty straightforward. So very first problem, make sure you have your user.name and your user.email. If you don't already have those values, it'll be very, very nice to do that. All right, quick solution, there you go. Here's me adding my user.name and my user.email. So hopefully everybody else has that.

[00:03:10]
Just to make sure I have that, I'll just copy these right now, throw them in there. Bada bing, bada boom, I got my git config user.name and user.email, the.primeagen@aol.com. Great email right there.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now