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

The "Creating a New Repo" 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 explains how to create a new git repository using the "git init" command. He demonstrates the process by creating a new repository and shows the resulting .git folder that is created. He also discusses the purpose of the .git folder, how it contains all the data structures, and the repository's history.


Transcript from the "Creating a New Repo" Lesson

>> Creating a repo, it's pretty straightforward. A lot of people probably have never actually created a repo, they've always just cloned from somewhere and worked on something. So if you've never done personal projects you may have never created one or if you always create it first on say GitHub or GitLab or Bitbucket, then you'll probably clone down from it.

Sorry, it's weird phrase to leave my mouth, BitBucket Cloud. So the very first step is Git init. Use Git init, to initialize Git. It will add a .Git folder inside the directory. And that's how you know it's a Git repo. So first problem, I want you to go somewhere and I want you to create your first repo.

You can name it whatever you want, I named this one myfirstgitrepo. And by the way, for those that are like, OK, I already know all the stuff I wanna move on fast, trust me, we're gonna go really deep, really quickly. I just wanted to make sure we're all on the same page with the exact same repo.

And so I'm gonna go Maketer my first repo, my first repo, and I'm gonna go Git, that was Git init. There we go. And long as you have everything properly set up, you should see this error message, which says, hey, by the way, you don't have a default branch name, here's the default branch name.

If you wish to do something with it, you can set your own config and it will magically work for you from here on out. So everyone should get this error message if you have the same setup that I do. So every single repo comes with this .Git folder.

This is where all the data structures kept. Now it's kinda weird because a lot of people probably think of data structures as things that run inside of a program, a tree, a hash map, but you can also keep them just in files, right? You got a question.
>> If you accidentally initialize that Git repo too high like at a parent folder, what's the best way to revert this?

>> The best way to revert that, delete the Git folder, right? Once the got Git folder has been deleted, the repo does not exist. All of Git's history is inside this .Git folder. So you delete that, you don't have a repo anymore. All right, problem. Validate you have a new Git repo by listing out all the files inside the .Git folder or directory.

Whatever one you wanna use, I've been in fact in one sentence just earlier. I said folder in your directory and I just realized how many people are they're just shook by the fact that I'm using those terms. I just love it. All right, so if you don't know you can use fine so if I go find out gifts, it will list out everything.

And you'll see a whole bunch of stuff in here. You'll see a bunch of informational tracking items, and then you'll also see a bunch of sample scripts right here. I'm not gonna talk about hooks today, I think hooks are evil. Don't use hooks that's my personal opinion. We're just not gonna cover them, if you wanna learn about hooks, go read right here you have a bunch of sample stuff they will just make your life miserable personal opinion.

Don't use hooks, okay? That's what your CI is for, that's your responsibility to test your own code, don't be ridiculous. All right. A lot of people have really strong reactions when it comes to hooks, either they absolutely love them or they hate them. I'm on the hating camp.

You may not like this, but this is what peak empty repo looks like, just a Git folder with a bunch of files in it. So, this was kind of mind blowing to me the fact that Git is in some sense stateless, like when you run Git, it has to go, okay, where am I?

It has to find the .Gitfolder. It has to look for that stuff and then it can tell exactly what's happened inside this directory by looking in the Git folder. And so that was kinda like a neat revelation to me that it is its own entity like that.

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