Part III: Chapter 3.1

git init

The Birth of a Repository

Every Git repository starts with a single command. But what does git init actually do? It does not connect to the internet, it does not scan your files, and it does not magically back up your project. It simply creates an empty hidden folder called .git.

The Boilerplate Setup

When you run git init, Git generates a boilerplate directory structure inside the .git folder. This folder is the entire brain of your repository.

If you delete the .git folder, your files remain intact, but you lose all your commits, branches, and history. If you copy the .git folder to a flash drive, you have copied the entire repository.

Interactive Explorer

Click through the files and folders that appear immediately after running git init to understand what each one is for.

Directory Tree
.git/
Select a folder or file to explore

Proving the Architecture

Let's create a brand new directory, run git init, and use the tree command to see exactly what Git just built.

Terminal
$mkdir my-new-project && cd my-new-project
$git init
Initialized empty Git repository in /my-new-project/.git/
$tree -a .git
.git
├── HEAD
├── config
├── description
├── hooks/
├── info/
├── objects/
│ ├── info/
│ └── pack/
└── refs/
├── heads/
└── tags/
10 directories, 4 files