All commands

git init

Turn any folder into a Git repository.

What it does

git init creates a hidden .git directory inside your project. That directory is the entire repository — every object, every pointer, every piece of history lives inside it. From this moment, Git can track what happens to every file in the project.

your-project/ · after git init
.git
├── HEAD
├── index
├── objects/
│ ├── info/
│ └── pack/
└── refs/
├── heads/
└── tags/

git init materializes the .git folder

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 3

Step 1

Choose an empty room

Point git at any folder — even one with nothing in it yet.

git init
your-project/ · after git init
.git
├── HEAD
├── index
├── objects/
│ ├── info/
│ └── pack/
└── refs/
├── heads/
└── tags/

A bare folder, before git arrives

Under the hood

1

Git creates the .git folder

git init writes a .git directory containing the four core structures: objects/ (empty), refs/ (empty), HEAD (a file pointing at refs/heads/main), and index (an empty binary staging file).

mkdir .git
mkdir .git/objects/{info,pack}
mkdir .git/refs/{heads,tags}
echo 'ref: refs/heads/main' > .git/HEAD
2

HEAD is born

HEAD is just a text file holding the name of the current branch. It points at refs/heads/main, but that branch file doesn't exist yet — it appears with your very first commit.

cat .git/HEAD  # → ref: refs/heads/main
3

Nothing is tracked yet

No objects exist. No files are in the index. Git simply says 'demonstrated' and waits. The working directory itself is untouched — Git is a layer on top, not a copy.

Aliases the pros type

Memorize the git init concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git init
AliasWhy people use it
g init

Common global alias where g = git.

gi

Bare initials some shells define.

g init -y

Some setups alias this to skip the default-branch warning.

Command anatomy

git init [<directory>]
<directory>

Initialize a repo in a specific folder instead of the current one.

-b <name>

Set the initial branch name (defaults to main).

--bare

Create a bare repo — no working directory, refs only. Used on servers.

When to reach for it

Starting a brand-new project and you want version control from day one.

You downloaded someone's code without a .git folder and want your own history.

You're exploring Git internals and want a clean sandbox: git init /tmp/lab.

Pro tip

Newer Git versions default the branch to main. To check: `git init -h` shows the default branch name as the --initial-branch hint.

Go deeper with