CurriculumGit Basicsgit init — Starting a Repository
Lesson 3 of 650%
Beginner6 min+60 XP

git init — Starting a Repository

git init is the very first command you run in any new project. It creates a hidden .git/ directory that transforms a plain folder into a full Git repository capable of tracking all your changes.

01.What Happens Under the Hood

Running git init creates a .git/ folder containing: HEAD (pointer to current branch), config (repository settings), objects/ (all your file snapshots stored as blobs), refs/ (branch and tag pointers). This directory IS your entire repository. Delete it and all history disappears — but your files remain untouched.

my-project/
📁my-project/
📁.git/← Git database
📄config
📄HEAD
📁objects/
📁refs/
📄README.md
📁src/

02.Two Ways to Start

You can git init an empty folder to start a brand new project, or run it inside an existing project to start tracking files that already exist. Git will NOT modify any of your existing files — it only adds the .git directory.

Commit Timeline
a1b2c3d
init
b2c3d4e
feat
c3d4e5f
fix
d4e5f6a
HEAD

Commands

commands — click to reveal output
$
mkdir my-project
Create a new project folder
$
cd my-project
Navigate into it
$
git init
Initialize the Git repository
▼ show output
$
ls -la
See the hidden .git folder
▼ show output
$
git init existing-project/
Initialize inside an existing project folder
▼ show output
KNOWLEDGE CHECK

What does git init create?

Rate this lesson:
PreviousNext Lesson